Exploring the Dialogs Controls in Vb.Net (Page 1 of 4 )
Dialog-box controls are an important part of programs, especially if you expect users to interact with your application. This article explains how to handle several different dialog-box controls.
Dialogs controls, or more correctly dialog-box controls, are controls that allow the user to interact with the program and retrieve information. They usually pop up when they are called, and allow you to choose a color from a color-pick dialog, or open or save a file through a dialog, and so forth. The user interacts with these at run time, and they present an interface from which the choice is made. They are related to the CommonDialog controls in VB6 and function in a similar way. However they are now based on well defined classes in the System.Windows.Forms name space as we shall see in this tutorial.
In the course of this tutorial you will see how they fit into the class structure. You will also try to understand their usage by means of an example which uses some of the properties and methods of these controls.
Accessing the controls in the IDE
When you create a WindowsApplication project and add a form to the project, you can see these controls in the Toolbox as shown in this picture. Besides these dialog-box controls there are three other dialog-box controls related to printing. These are not covered in this tutorial. While these are built-in controls, it is also possible to create user defined or custom dialog-box controls. Custom dialog-box controls are also not considered.

These controls are like any other controls; they can be dragged and dropped on the form. However, they are not visible items and find themselves in a tray below the form as shown in this picture, where one each of these controls have been placed on the form, Form1.

FontDialog Control
As the name implies, this control, when called up, brings up a familiar dialog box, Font, from which a variety of choices regarding fonts can be made as shown in this picture. When you click OK to this screen, your font choices will be applied to a string in some part of your program.

This next picture shows you the class view of the FontDialog class with all the members shown on the right. You can use the New() method to instantiate this object and set its properties and methods. You may notice its hierarchical relationship with the CommonDialog controls.

Create a WindowsApplication Project, add a form to it and name it suitably. Add a button and a text box control to the form. Drag and drop a FontDialog Control onto the form and it will immediately move to the tray underneath the form. To the click event of the button type in the following code:
Private Sub Button2_Click(ByVal sender As System.Object,
ByVal e As _ System.EventArgs) Handles Button2.Click
FontDialog1.ShowDialog()
'FontDialog window pops-up If Windows.Forms.DialogResult.OK Then
Me.TextBox1.Text = "Viva la Republica!"
Me.TextBox1.Font = FontDialog1.Font End If End Sub
When you build the project and run the program the form pops up. If you now click on the button which has the above code in its click event, the FontDialog window shown earlier pop ups. When you make your choice and click on the OK button your choice will be applied to the text box's font. FontDiaog1.Font has all the selected features. For the picture shown next the choices were, Font: Lucida Console, FontStyle: Bold, Size:11, and Effects: Underline as seen in the next picture. Of course the text box size will not accommodate whatever size you choose, although at design-time the text box size is related to your choice of the font, with the default being Microsoft MS.

Next: ColorDialog Control >>
More Visual Basic.NET Articles
More By Jayaram Krishnaswamy