Common dialog class is the base class for displaying common dialog boxes. One can access these boxes like Font dialog box, Open dialog box, Print dialog box etc. by using inherited classes of this base class. All these inherited classes overrides RunDialog() method which is automatically called when user calls the ShowDialog() method.
To add this box just drag-n-drop color dialog control from the toolbox. Add a textbox and two buttons on the form with text property background and foreground respectively as shown in the following image:
Write the following code snippet (C# language) in click event of both button respectively:
So it is so easy to change color of any control’s background or foreground property.
FontDialogBox Control
Color Dialog Box
To change the color of anything you want like text color, background color or foreground color of any control dynamically, we can use color dialog box. A simple look on color dialog box:To add this box just drag-n-drop color dialog control from the toolbox. Add a textbox and two buttons on the form with text property background and foreground respectively as shown in the following image:
Write the following code snippet (C# language) in click event of both button respectively:
private void backgroundButton_Click(object sender, EventArgs e)
{
colorDialog1.ShowDialog();
textBox1.BackColor = colorDialog1.Color;
}
private void foregroundButton_Click(object sender, EventArgs e)
{
colorDialog1.ShowDialog();
textBox1.ForeColor = colorDialog1.Color;
}
Now look out the text box, it have been changed its background color to and also foreground color as shown in following image.{
colorDialog1.ShowDialog();
textBox1.BackColor = colorDialog1.Color;
}
private void foregroundButton_Click(object sender, EventArgs e)
{
colorDialog1.ShowDialog();
textBox1.ForeColor = colorDialog1.Color;
}
So it is so easy to change color of any control’s background or foreground property.
FontDialogBox Control
Tidak ada komentar:
Posting Komentar