To choose a color using ColorDialog in C# and VB.NET you can use the following snippet.
Sample C#
using (var colorDialog = new ColorDialog())
{
if (colorDialog.ShowDialog() != DialogResult.Cancel)
{
var colorChosen = colorDialog.Color;
textBox1.ForeColor = colorChosen;
textBox1.BackColor = colorChosen;
}
}
Sample VB.NET
Using colorDialog = New ColorDialog() If colorDialog.ShowDialog() <> DialogResult.Cancel Then Dim colorChosen = colorDialog.Color textBox1.ForeColor = colorChosen textBox1.BackColor = colorChosen End If End Using
RT @CodeSnippetsNET: How to choose a color using ColorDialog in .NET http://t.co/ec4PSsIK2Z #csharp #vb #dotnet #dev