Tuesday, 1 June 2010

To access the default instance of a form at run time (Visual Basic only)
1. Refer to the form by its name. You can call methods or access properties from this default instance. For example:
' VB
Form1.Text = "This is my form"
Form1.Show()
2. If referring to a form from within that form’s code, you cannot use the default instance. You must use the special keyword Me (Visual Basic) or this (C#) to access the form’s properties and methods.
To access a form’s methods and properties from inside its code
1. Use the keyword Me (Visual Basic) or this( C#). For example:
' VB
Me.Text = "J and J's Wine Shop – Main Page"
// C#
this.Text = "J and J's Wine Shop – Main Page";
2. You can also create new instances of forms at run time by declaring a variable that represents a type of form and creating an instance of that form.
To add a form to your application at run time
1. Declare and instantiate a variable that represents your form. This example assumes that you have already designed a form named Form1 in your project:
' VB
Dim myForm As Form1
myForm = New Form1()
' Displays the new form
myForm.Show()
// C#
Form1 myForm;
myForm = new Form1();
// Displays the new form
myForm.Show();
Properties of Windows Forms
The visual appearance of your user interface is an important part of your application. A user interface that is poorly designed is difficult to learn and will, therefore, increase training time and expense. You can modify the appearance of your user interface by using Windows Forms properties.

No comments:

Post a Comment