[.net] C# tool development

Started by
13 comments, last by realJJ 19 years, 9 months ago
Hi, I've been looking everywhere for a good tutorial on how to make a windows application with C# and winforms. I'm wanting to make a simple 2D map making tool. Most of the examples I find are how to make a web browser. Has anyone found any in-depth tutorials on setting up various kinds of window apps?
-- master_ball --------------------------------student seeking future game dev career, advice welcome
Advertisement
If you have Visual C# .NET, you can simply use the Form Designer to design your layout visually.

If you don't have the luxury of having a fancy IDE, and if you are using DX9, check out the SDK examples under C# and DirectDraw to get you started. There's a basic one under my installation path: "C:\DX9SDK\Samples\C#\DirectDraw\Windowed".
"If I have seen farther than other men, it is because I have stood on the shoulders of giants." -- sir Isaac Newton
I can lay things out with the Form Designer, I have set up a main menu, and see how to tie in the code. Is there an easy way to do a OpenFile Dialog? I know how to call this in Win32, is there a way in C# with the Form Designer? If not is there a C# call for that dialog? Thanks@!
-- master_ball --------------------------------student seeking future game dev career, advice welcome
View->Toolbox, then Windows Forms->Open File Dialog.
"If I have seen farther than other men, it is because I have stood on the shoulders of giants." -- sir Isaac Newton
System.Windows.Forms.OpenFileDialog.ShowDialog

ld
No Excuses
private void FileOpen_Clicked( object sender, System.EventArgs e ){    System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog();    DialogResult res = ofd.ShowDialog( this ); // This will make the ofd steal your mainwindows focus.                                                // You want this.                                /* This code gets executed after the ofd closed */    /* So let's wait.. */    /* Hmppff.. */    /* DONE!! */        if( res == DialogResult.Ok )    {      /* Yay! */    }}
Go to www.windowsforms.com for beginners tutorials on how to build Windows Forms applications.

You can also check www.codeproject.com
-----------------SloGameDev.net | My homepageQ:What does a derived class in C# tell to it's parent?A:All your base are belong to us!
The code shown by Pipo TheClown is flawed, since the OpenFileDialog/SaveFileDialog are unmanaged resources. And you are required to release unmanaged resource yourself.

There are 2 ways of doing it. The first one is doing it yourself:
OpenFileDialog dlg = new OpenFileDialog();if (dlg.ShowDialog() == DialogResult.OK){    MyObject.Save(dlg.FileName);}dlg.Dispose(); // Release


The other way is by taking advantage of the C# language keyword "using":
using (OpenFileDialog dlg = new OpenFileDialog()){    if (dlg.ShowDialog() == DialogResult.OK)    {        MyObject.Save(dlg.FileName);    }} // <- End of "using" scope, dlg.Dispose() will auto called


Toolmaker

Quote:Original post by Toolmaker
The code shown by Pipo TheClown is flawed, since the OpenFileDialog/SaveFileDialog are unmanaged resources. And you are required to release unmanaged resource yourself.

Em. Where did you get this idea? System.Windows.Form.OpenFileDialog is part of the core .NET framework. I have difficulty imagining how it's going to be unmanaged...

Checking the MSDN page, I don't see any remarks on the subject, either...

ld
No Excuses
Quote:Original post by liquiddark
Em. Where did you get this idea? System.Windows.Form.OpenFileDialog is part of the core .NET framework.

The OFD ultimately derives from Component. The docs for Component state:
Quote:
It is recommended that a Component release resources explicitly by calls to its Dispose method, without waiting for automatic memory management through an implicit call to Finalize. When a Container is disposed, all components within the Container are also disposed.

If you add an OFD to the form itself, the designer will create code to ensure it's disposed with the form(by adding it to the Container components instance - Take a look at YourForm.Dispose).
Quote:
I have difficulty imagining how it's going to be unmanaged...

It's a wrapper around the Win32 file dialog.
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]

This topic is closed to new replies.

Advertisement