- This topic explains about the working of Color Dialog in vb programming.
- Tools used in the working of Color Dialog in vb: Button1 (Button1), RichTextBox1 (RichTextBox1), ColorDialog1 (ColorDialog1).
RichTextBox – Working of Color Dialog in vb
- In RichTextBox, they are similar to TextBoxes, but they provide some advanced features when compared to standard TextBox in VB.NET.
- In RichTextBox, it allows text formatting, including color change, font change to a particular text in the RichTextBox.
- Using RichTextBox, we can create our own word processors. In RichTextBox, it allows user to enter and edit text.
- Text can be directly assigned to the control or can be loaded from a RichText Format (RTF) or plain text file.
RichTextBox Syntax
|
1 2 3 4 5 6 |
'Declaration <ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _ <ComVisibleAttribute(True)> _ <DockingAttribute(DockingBehavior.Ask)> _ Public Class RichTextBox _ Inherits TextBoxBase |
ColorDialog Class – Working of Color Dialog in vb
- Color Dialog class represents a common dialog box that displays available colors along with controls that enable the user to define custom colors.
Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
- Syntax Working of Color Dialog – Working of Color Dialog in vb
|
1 2 3 |
'Declaration Public Class ColorDialog _ Inherits CommonDialog |
ColorDialog.ShowDialog Method – Working of Color Dialog in vb
- Helps to run a Color Dialog Box with a default browser
ColorDialog.Color Property – Working of Color Dialog in vb
- Gets or sets the color selected by the user.
- Syntax for ColorDialog.Color
|
1 2 |
'Declaration Public Property Color As Color |
Change Back color of a RichTextBox – Working of Color Dialog in vb
|
1 2 3 4 5 |
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If ColorDialog1.ShowDialog() = DialogResult.OK Then RichTextBox1.BackColor = ColorDialog1.Color End If End Sub |
Change font color of a RichTextBox – Working of Color Dialog in vb
|
1 2 3 4 5 |
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If ColorDialog1.ShowDialog() = DialogResult.OK Then RichTextBox1.ForeColor = ColorDialog1.Color End If End Sub |
Change color of a selected text of RichTextBox – Working of Color Dialog in vb
|
1 2 3 4 5 |
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If ColorDialog1.ShowDialog() = DialogResult.OK Then RichTextBox1.SelectionColor = ColorDialog1.Color End If End Sub |
Change back color of a selected text in RichTextBox – Working of Color Dialog in vb
|
1 2 3 4 5 |
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If ColorDialog1.ShowDialog() = DialogResult.OK Then RichTextBox1.SelectionBackColor = ColorDialog1.Color End If End Sub |






