The ColorDialog Control
The ColorDialog (System.Windows.Forms.ColorDialog) is used when you want to pick different colors. For example, when you want to pick for color of the font or a background color for the form, you can use the ColorDialog control.Properties | Description |
---|---|
AllowFullOpen | Specifies whether the user can choose custom colors. |
Color | The color that the user selected. |
CustomColors | A collection of custom colors picked by the user. |
FullOpen |
Specifies whether the part used to pick custom colors are automatically open.
|
The window initially composed of predefined color palettes. You can click the Define Custom Colors button to reveal more colors where you can pick every color you can think of. You can even provide the Hue, Saturation, Luminance values, or RGB values. The main window allows you to choose colors while the right slider adjusts the brightness of the color. You can click the Add Custom Colors button to put the selected color to the Custom Colors pallet so you can reuse it later.
Drag a ColorDialog control to the form. It will not be visible to the form but you can find it a the bottom section of the Designer.
To change properties of the ColorDialog control, click it in the designer and proceed to Properties Window.
Double click the button to create an event handler for its Click event. Use the following code for the event handler.
private void button1_Click(object sender, EventArgs e) { DialogResult result = colorDialog1.ShowDialog(); if (result == DialogResult.OK) { this.BackColor = colorDialog1.Color; } }
The first line of code calls the ColorDialog's ShowDialog static method. This method shows up the color dialog where the user can pick a color. This method returns a System.Windows.Forms.DialogResult value which indicates whether the user clicked the OK or the Cancel button of the Dialog. If the user clicked color and pressed the OK button, the dialog closes and the color the user picked is stored in the Color property of the control. We test the value of the result to determine if the user clicks the OK button. If so, we changed the background color of the form to the color the user picked using the value of the Color property.
Do you know:-
- How to Retrieve data using dataset in c#
- “Login failed for user” SQLConnection using C#
- How can I prevent the browser back button After Logout
- Calendar Control in c# Windows Application
- Timer tick event in c# windows application
- How to delete record in c# using the connected approach
- [Connect] to Database c# Through Code
- The Command Class | C# | TrickCode
- C# DataReader ADO.NET |Trickcode
- What is disconnected data access?
- how to Adding Parameters to Commands
- SQL Basics?
- What is Database Preparations?
- SQL vs NoSQL or MySQL vs MongoDB
- What is data provider in C#?
- What is connection string C#?
- [SQL] SELECT Statement | Example
- how to get return value from stored procedure in sql server
- how to prevent sql injection attacks
- What is Database? What is SQL?
- C#.Net How To: Send email in asp.net using c#
If you like the tutorial, then please share this tutorial with your friends on social media.
Post A Comment:
0 comments: