Hi,
Can you please take a look at following code and let me know how I can restrict the "txtColor.Text" in a way that if user insert a wrong hex sting(value) like "KKKKKK" the exception handler handle the issue and pops a warning message to correct the input?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace SimpleColorPicker
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void txtColor_TextChanged(object sender, EventArgs e)
{
if (txtColor.Text == "")
{
lblColor.ForeColor = System.Drawing.Color.MediumPurple;
}
else
{
string cc = String.Format("#{0}", txtColor.Text);
Color col = System.Drawing.ColorTranslator.FromHtml(cc);
lblColor.ForeColor = col;
lblColor.Refresh();
}
}
}
}
Thanks