Community Server

The platform that enables you to build rich, interactive communities
Welcome to Community Server Sign in | Join | Help
in Search

hakimin

Form.Show or .ShowDialog or .Application.Run(Form)

Chapter 1 in Window Forms 2.0 Programming.

What the book talk about. Ermmm from the reading, i got a very clear view of Windows Form 2.0 programming. As example have been show, i know a little bit basic of Form under System.Windows.Form.

So for today, i will give a very simple example of Windows Form programming as a basic to me and all. For this first blog of Window Forms 2.0 Programming.
First of all i will tell about Form. What is it?. We can create an application without using a form. Form is just an interface that communicate user with the computer system. An application without a form will be simple boring because user will se a text only. By using a form, a sofware developer can create an interface which will make user fell glad to using an application. A form can be a dialog box, message box, sigle document interface (SDI) windows or a multiple document interface (MDI) windows. It can be more complicated as we can se windows application today. That the explanation about windows form. So i will give a simple example creating a windows form application.

Example :

class FormApplication
{
    static void Main()
    {
       System.Windows.Forms.MessageBox.Show("Hello, Form Programming");
    }
}

so that is the very simple windows form programming. But now a day, we can not use a very long statement as System.Windows.Forms to get a message box from Form library. In C# we can use 'using' to call the System.Windows.Forms namespace. So what we have to do is

Example :

using System.Windows.Forms;

class FormApplication
{
    static void Main()
    {
       MessageBox.Show("Helloo, Form Programming");
    }
}

the code so easy to read and we the developer will be easy to maintain. So lets procceed to our main topic. The example shown is very simple form application. We can create a complex application, but before that i want to show a three diffrent way to show a form windows.

Example 1 :
using System.Windows.Forms;

class FormApplication
{
    static void Main()
    {
        Form form = new Form();
        form.Show();
    }
}

this way we can show the form application but it not the best way to use it. Because it will prompt returns and exist the process. So if you want to show a form modeless, you can use that approach. "Show" the form. If you want to show form "modally", see this second example. Modally meant the form will be shown until user close it, an it will return to the Main method. It use "ShowDialog" method.

Example 2 :
using System.Windows.Forms;

class FormApplication
{
    static void Main()
    {
        Form form = new Form();
        form.ShowDialog();
    }
}

but this one its not the one you maybe want to use if you are building an application. Because it not accessible to other parts of your application. So to make it real and contect with you application, pass the main form as an argument to the Application objects static run as example below.

Example 3 :
using System.Windows.Forms;

class FormApplication
{
    static void Main()
    {
        Form form = new Form();
        form.Text = "Hello Form Application";
        Application.Run(form);
    }
}

so many things you can do more. But i will write more about. Enough at this for an enterview

Adios
Published Friday, November 03, 2006 8:31 AM by hakimin

Comments

No Comments
Anonymous comments are disabled

About hakimin

Software Developer
Powered by Community Server, by Telligent Systems