Creating Windows Applications
.NET Remoting

Creating Windows Applications

Windows Forms is the new platform for Microsoft Windows application development, based on the .NET Framework. This framework provides a clear, object-oriented, extensible set of classes that enable you to develop rich Windows applications. Additionally, Windows Forms can be used to connect to a Web Service or an ASP.NET application.

Windows applications run locally on a user's machine. .NET has a rich set of classes to create sophicated programs. Visual Studio provides many features which allow creating Windows applications easily. As you've seen with ASP.NET application you can drag and drop controls.

Demo

Let's create a Windows application that makes use of the Web service validator.

  1. From the main menu select File | New | Project

  2. Select Visual C# Projects and Windows Application.

  3. Press OK.

  4. From the main menu select View | Solution Explorer.

  5. Right-click on References in the Solution Explorer and select Add Web Reference.

  6. Type: http://localhost/webservice1/service1.asmx. into the URL field.

  7. Press Add Reference.

  8. From the main menu select View | Toolbox.

  9. Drag on a couple of Label controls for User Name and User Password.

  10. Drag on a couple of Text controls for the web user to enter a user name and password.

  11. Drag on a Button control to validate the user name and password.

  12. Double-click on the login button to add server-side code:

    private void button1_Click(object sender, System.EventArgs e)
    {
        localhost.Service1 ws = new localhost.Service1();
    
        bool login = ws.ValidatePassword(textBox1.Text,textBox2.Text);
    
        if (login == true)
        {
            MessageBox.Show("Successful login");
        }
        else
        {
            MessageBox.Show("Unable to login");
        }
    }

  13. Press F5 to run the application.

What if I wanted to display the login status in a status bar?

  1. Drag a StatusBar control to the bottom of the windows form.

  2. Double-click on the login button to modify the server-side code to make use of the status bar:

    private void button1_Click(object sender, System.EventArgs e)
    {
        localhost.Service1 ws = new localhost.Service1();
    
        bool login = ws.ValidatePassword(textBox1.Text,textBox2.Text);
    
        if (login == true)
        {
            statusBar1.Text = "Successful login";
        }
        else
        {
            statusBar1.Text = "Unable to login";
        }
    }

  3. Press F5 to run the application.

What if I wanted to display an icon in the Task Tray in the lower right-hand corner?

  1. Double-click on the NotifyIcon control.

  2. Set the Visible property to false.

  3. Set the Icon property by clicking on the ... button to C:\Program Files\Microsoft Visual Studio .NET 2003\Setup\Setup.ico.

  4. Double-click on the login button to modify the server-side code to make use of the notification icon:

    private void button1_Click(object sender, System.EventArgs e)
    {
        localhost.Service1 ws = new localhost.Service1();
    
        bool login = ws.ValidatePassword(textBox1.Text,textBox2.Text);
    
        if (login == true)
        {
            statusBar1.Text = "Successful login";
            notifyIcon1.Visible = true;
        }
        else
        {
            statusBar1.Text = "Unable to login";
            notifyIcon1.Visible = false;
        }
    }

  5. Press F5 to run the application.

Overall, it is quite easy to create Windows applications in .NET.

    
Copyright 1999-2017 by Cstructor LLC. All rights Reserved.