I'm trying to learn C# from some YouTube videos, but I have a few concerns. I started with JavaScript, wanted to learn a software language, so I learned some C++, but then I found out that C# is better for GUI programming, so now I'm going with that.
The problem is that I feel like VS is doing a lot of things I should know how to do but don't... When I add a button or create a new class or something it's all done with VS. I want to know what it's doing, though, so I can do it myself if I need to.
I'm on the video explaining classes, and I was wondering where the header file was. I couldn't find it, so I searched online and, come to find out, unlike C++, C# doesn't have header files. Are the class files automatically linked?
Is it practical to learn how to do everything manually, or is C# done solely in VS anyway? Is there a way to keep track of what files and code snippets are added and created when a button is pressed in VS?
I am bias, but the best way to understand and learn what is going on in a program is to debug it.
Creating a new C# app in Visual Studio will give you the fastest path to this. You shouldn't have to worry too much what Visual Studio is generating for you, because if you want to understand it, simply step through the code in the debugger. You can see exactly what calls are being made, how each of them changes state, etc, etc.
If you make a basic GUI app, then step through the InitializeComponents function, that gives you a really good sense of how VS sets things up for you.
C# can be used outside of VS, but having all the components so you can just hit F10 and starting stepping away in the IDE makes it the best choice.
Well, best way would be to not use the VS Designer, if you want to learn what happens behind the curtains. You may of course code every single line by hand and it still will work. Eg. to add a button:
Form form = new Form(); // create my form
Button button = new Button(); // create the button
button.Text = "Click me!"; // add some text
form.Controls.Add(button); // add the button to the form
Application.Run(form); // start the applications main thread and display the button
There are dozens of tutorials outside, just find the one that suits you best.
The thing is that visual studio is giving you all the preregistered stuff in built. So you just need to build your own class templates the definition will be presented to you default.
So if you create a class call employee it will create basic syntax for you and you need to write the logic directly.
Thanks,
Jigar
C# as a language is used to develop several kinds of applications such as console-based applications, Windows desktop applications and Web applications.
For the former, you will code everything mostly by hand, even if you are using Visual Studio.
For the latter two, since they are GUI based, it's recommended to use Visual Studio so that you can use the drag-and-drop approach as well as have Visual Studio take care of the routine tasks so that you can focus on the logic and actual development.
IMO, you shouldn't try to learn everythin, but anyway - core concepts will broaden your understanding and will surely help you in further dev-life.
If you want what exactly VS do with your code - put some "VCS guard" at top of project. Use Git or Mercurial and you could see exact changes that was applied to each file (commit everything before you going perform interesting action and check changes after). It could help you to track anything that will happens with your project. But for most cases its not very productive to do everything by hands. DevTools were made to remove very bored routine.
Its very useful to know how you can do something without VS installed, but all such tasks is usually not directly related to programming, mainly its some kind of supporting stuff.
Ex. how build a project with msbuild or csc.exe (C# compiler) to setup homebrew continuous integration system.
If you want really deep grasp into .NET - read CLR via C# by Jeffrey Richter. IMO it's far more important to know system guts than to know how to place button on the form without VS-designer.
Related
I have a Windows Form Project and I need to create an installer for the same. I need to add prerequisites like .net 4.5 and vC++ redistributables.
The basic issue is that I need the installer to work offline as well as online, and in those scenarios I need it to move through different dialogs that accept different sets of input from the users. Further, for offline verification task, a certain code is generated after the users have initially entered some inputs.
I need to ask if Wix should be used for this or should I use something else, and if Wix will be useful for resolving my above-mentioned issues.
a) Can I have condition based movement between dialog boxes?
b) Can I write custom code between dialog boxes to perform a certain task, after the installation has been initiated?
P.S. - I haven't worked with Wix before, so links that might help me in building the installer will be of real help.
#Prashant,
1) Have you looked at Conditional Statements yet? Here's a pretty good example that covers a lot of what you're trying to do.
How to install features depending on the value of property
http://wixtoolset.org/documentation/manual/v3/xsd/wix/condition.html
2) Depending on what tasks you are trying to perform, there might be an existing Wix Component that covers it. If not, you can also execute Custom Modules as illustrated here.
http://wixtoolset.org/documentation/manual/v3/xsd/wix/customaction.html
http://wixtoolset.org/documentation/manual/v3/wixdev/extensions/authoring_custom_actions.html
https://blogs.msdn.microsoft.com/jschaffe/2012/10/23/creating-wix-custom-actions-in-c-and-passing-parameters/
How to add custom action to wix setup project
3) Are you aware of the following resources?
https://github.com/deepak-rathi/Wix-Setup-Samples
https://github.com/tom-englert/Wax
https://github.com/rstropek/Samples/tree/master/WiXSamples
There should be more than sufficient information here to get you going.
I would like to know if there is any way to extend the task manager in a language like C# preferably but i'm also ok with C++, or anything else that works.
I would like to add some new features like, search, kill all processes with the same name, and what ever else comes to mind, but i have no idea were to start.
Note: I don't want to replace it or rewrite it from scratch, just add some new features.
I also found this link Is it possible to add functionality to Vista/7 taskmgr.exe? but it's for VIsta/7 i'm just hoping something change in 8, considering that it was completely redesigned.
Thank you
If i am correct, what you want to know is if there is a way to extend TaskManager via a plugin based approach( like Office/Ie/Outlook plugins).
The answer is no.
I however have a different approach which may help you do what you want but would be a lot more work.
What i suggest is Com interop based injection and override.
using Spy++ you can see what are the window classes/properties of the TaskManager window. Then you would need to write a program which works minimized(system tray?!) and watches for some identifying window/class name to pop up in the messages system. Windows messages can be intercepted and hooked. http://www.codeproject.com/Articles/33459/Spying-Window-Messages-from-the-Inside may be of some help.
Once you get your window handle. you will probably need to find the tabs control group. and inject a new tab element. Post which you can put anything which you deem into the tab element.
This is speculative, and involves the assumption that all the new changes you want to add would end up in a new tab.
I hope this helps you in some way.
PS: The answer is not totally speculative though. For some internal use at my workplace, I had made a prototype which would do something similar to outlook and override some default functionality which wasn't exposed by the Add in framework per se. Beware that this would require lots of testing and was somewhat unreliable/unstable
So, I made a program in Visual C# 2010 Express. Finished enough to work, and pretty darned good for my first attempt at the language. But then I foolishly decided, "Hey, this program needs a close confirmation dialog before I send it out!" So I write the function, and then I go into the auto-generated code to bind said function appropriately.
KABOOM!
Now, the form designer shows a blank form, and all those shiny components have all been erased from both the designer and the auto-generated code. Which, in such a simple program, is about 80% of the work I put into it.
Now, in NetBeans, I would right-click the file's tab, and just go back to a previous version, maybe losing about 15 minutes of work. This is a pretty obvious concept, I'm just not sure where to find file history in Visual Studio. So, where is the equivalent so I can get my work back?
(I've also managed to get my code back by just undoing a whole bunch - but the designer doesn't see it, and neither does the compiler, so it still builds to a blank form.)
Sadly, you've just learned a couple of things.
One is to never, ever modify designer-generated code. In fact, C# has a concept called partial classes which allow you to modify a generated class without having to modify the generated file.
Second, that Visual Studio in and of itself has no built in source code control -- you need to choose the one you like and be diligent in using it. Some of the most popular are git, subversion, mercurial, and Team Foundation Server. I personally use svn, but the others are good too. Avoid something called Visual SourceSafe (VSS).
From the sound of it, I'd say you tried ctrl-z until some point in your code, but not in the designer?
Performing multiple "undo's" in the code-behind file where you put your code is one thing, performing "undo's" in the designer is another.
Hopefully, you have not closed visual studio yet, and viewing your now blank form in design view, and trying a bunch of ctrl-z presses there, might do the trick.
Actually the controls are not lost from Design code or Initialize
Component() ,make sure that whether check
Initialize Component() { this.controls.add("Where the control was ")
}
Example:
1-this.Controls.Add(this.panel1.label1); 2-this.Controls.Add(this.panel1.label2);
either in form you can write like below
should write in the Initialize Component()
this.Controls.Add(this.label1);
I had a similar effect: the code wasn't lost because the project compiled perfectly but I only got a blank form in designer.
This was because the form was inherited from another form, and I added in the Load event of the base form the line: this.MdiParent = Application.OpenForms("BaseForm");
After deleting this line (and recompiling) I could access the design of the descendig forms again.
One thing you could do, it won't help you this time, but may be a good idea for the future - if you copy your code alot (like I do), get one of those clipboard savers - like ClipTrap (which is lightweight, simple, and great).
Then, if you realize you can't undo what you did, then you get a second chance by running through the "trapped" text to see if what you want might just be there.
Another good option is to try something like AutoVer, which will save a copy of any changed file (or files in a folder) every so often as you like. This could provide you with a backup of your codefile, or even the entire project - every five minutes, or every minute as long as something has been changed. Awesome program. This is a certain fashion of source control, or at least source backup.
(And no I'm not the authour of either application)
However, for your particular problem, if the code is still there in your designer.cs page - maybe you just erased a reference or a namespace. Make sure the namespace matches, and make sure your in your form's code file, that the InitializeComponent(); function is being called (that's what places all the designer's controls onto the form, you know).
In the code behind file click 'undo', not in the designer window. Accept the warning, and when the code comes back, the form should be back to normal, Visual Studio 2015.
I'm writing in Visual Studio 2008 using C# (if that makes a difference) and I have the following snippet of code:
if(saveFileDialog1.ShowDialog() == DialogResult.OK)
{
//Write Stuff to File Here
}
For a while I thought my code that wrote the file was taking forever, however upon debugging it seems to take forever (5 to 10 seconds) just to step between the "if" statement and the first bracket of first code within the "if".
Is there anything I'm doing wrong? Is there any difference between creating the saveFileDialog object in the UI versus creating it on the fly (through code)? Would it make a difference if there is no "else" statement?
Any thoughts or ideas would be greatly appreciated!
This is not unusual, on many machines a ton of DLLs get loaded into your process when you use that dialog. You can see them getting loaded by using Project + Properties, Debug tab, tick the "Enable unmanaged code debugging" checkbox. The Output window shows a trace of every DLL that worms its way into your program.
These are shell extensions, customizations for Explorer. The dialog you use is a shell dialog, you surely recognize the similarity with regular Explorer views. Things like icons and context menus behave the same. Having a lot of shell extensions installed is common on developer's machines, more so than user machines. There are a lot of them out there, offering such conveniences as integrating whatever tool you like to use with Explorer itself.
Debugging the problem isn't that easy, you won't have the actual source code for these extensions. You might get a hint about the troublemaker from the trace in the Output window. If there's a lengthy pause after one particular DLL then odds are good that this DLL is the source of the problem. Nothing really solid though.
The better approach is to use SysInternals' AutoRuns utility. It shows you exactly what shell extensions are installed and allows you to disable them by simply clicking a checkbox. Start disabling anything that doesn't have a Microsoft copyright and stuff you could live without. Logout + Login required to make the changes effective.
I wrote a console program in c# that takes up to three files as input, and does some data calculations on them.
I'd like to make a simple frontend that allows the user to easily
import files - basically choose up to three files to be routed to the backend code
change settings - I have about 10 settings that I'm currently storing in an app.config file. maybe a simple settings box would be nice
see what's going on - the console program shows some status messages that might be useful to display on a GUI
I have practically no experience with windows forms or GUI design, so I really don't know where to begin. I compiled the backend stuff into a *.dll and am currently playing around in design mode of sharpdevelop...but i really have no idea how to get the two to work together.
any pointers would be greatly appreciated!
The usual pattern, in cases like these, is to make the main features of the application into a class library and call that from a wrapping executable, such as a console app, winforms app or webforms app (if possible). That way you can easily adapt the interface as needed and simply route input and output to and from the class library.
Edit: I realize this isn't a very indepth answer, but I hope it helps to get started at least, together with any other answer that may arrive.
If you want to get started with GUI design in .NET, I recommend you choose WPF (Windows Presentation Foundation). This is the latest technology released in the UI/graphics area by Microsoft and is where everything is heading now. (Windows Forms won't be obsolete for a long time, though it is surely but slowly becoming deprecated.) I noticed however that you are using SharpDevelop, which doesn't yet have real support for WPF (as far as I know), whereas it certainly does for WinForms. If there's any chance you can use Visual Studio, I recommend you begin by learning WPF. You have the advantage of not being confused by previous experience with the styles and methodologies of WinForms, so it would very much be the right way to go.
Whichever you wish to learn, the Getting Started page of WindowsClient.NET (the official MS site for both WinForms and WPF) would be a great resource. There's also a few MSDN articles on getting started with WPF.
Hope that helps.
Have you tried Visual Studio Express editions? They're free and come with a designer for either WinForms or WPF applications.
As a first pass you'll need 3 text areas for the filenames, with associated buttons to bring up the file open dialog (it doesn't actually open the file just returns the filename).
A label to display the status - updated from your worker code.
Then either the various radio buttons, check boxes etc for your configuration settings.
Oh and don't forget the "Start" button to set off your process.
If your process takes a while you ought to use a background worker thread. You can then implement a "Cancel" button to safely abort the process and tidy up if it goes wrong.
There will be optimisations and reorganisations that you can do once you've got it working.
Your question is quite indistinct. If you're asking about working with GUI, you should read some book on Windows Forms.
And if you're asking about how to put your dll in your new windows forms application, then you should just add a reference to it in winforms project's properties and then use classes from dll's namespace.