Exploring the Dialogs Controls in Vb.Net - ColorDialog Control
(Page 2 of 4 )
Again as the name suggests, when this control is called up, it will show a color-pick dialog, Color, where you can pick a color that can be applied to the object's color related properties. This can be the backcolor of a text box for example, or the form's backcolor, or forecolor, and so forth.

The next picture shows the class view of the ColorDialog class. Again you can trace it back to the CommonDialog control in the inheritance chain. There are many properties, out of which only the Color() property is used. The ShowDialog() is however inherited from the CommonDialog.

Now to the above project add another button, and after dragging and dropping a ColorDialog control onto the form, add the following code to the click event of the button:
Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As _ System.EventArgs) Handles Button1.Click
ColorDialog1.ShowDialog() If Windows.Forms.DialogResult.OK
Then Me.TextBox1.BackColor = ColorDialog1.Color End If End Sub
The first line of code, ColorDialog1.ShowDialog() pops up the Color pick window shown earlier. When you make the choice and click OK, the Windows form gets the message and applies the ColorDialog's Color() property (the color chosen) to the Backcolor property of the text box control. When you build and run the form, it shows with the two buttons, one for the font and one for the color. Clicking the Font button creates some text in the text box, and by clicking the color button and applying a light blue color you will see the following.

FolderBrowserDialog, OpenFileDialog and SaveFileDialog Controls
These dialogs will be briefly discussed, and in the last part of the project all these controls will be used, which accomplishes the following. The FolderBrowserDialog Control will open a browser from which a folder will be chosen. The OpenFileDialog will open a file from the folder and will be passed on to a web browser control to display a web page. The chosen file can then be saved to a chosen location using the SaveFileDialog control.
FolderBrowserDialog Control
When you call up this control it will pop up a Browse For Folder dialog as shown in the next picture, from which you can choose a folder, a sub-folder and any other nested folder. The path to this folder is now captured in this object's SelectedPath() property which can be accessed by code.

This next picture shows you the class view of the FolderBrowserDialog class and its members in the right panel. You can instantiate using the NEW() keyword.

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