So I'm trying to create a small program where when you click in an empty text box a dialog box will appear and change the background of the text box. Now I've tried to use the bellow code but it does nothing. The textbox is in read-only mode. Any help is very appreciated.
private void textBox1_Enter(object sender, System.EventArgs e)
{
colorDialog1.ShowDialog();
textBox1.BackColor = colorDialog1.Color;
}
(if you are using Windows Forms (which I'm assuming you are), you should tag it, and you shouldn't have a "Visual Studio" tag)
If I create a Windows Forms app, drop a textbox and a Color Dialog on the form, and add this code:
...up pops the Color Dialog. If I pick a color and press OK, the back color of the text box changes. I tried this with and without ReadOnly set to true (I was surprised you can "Enter" a read-only text box, but...).
So, are you seeing the color dialog pop up and you select a color and press OK and then you see nothing? That's surprising. Or, are you seeing something else?
For what it's worth, this is not a great UI design. I don't expect another dialog to pop up as the result of clicking in a textbox. Also note that this may only happen once. Once you have clicked in the text box, you have entered it. You have to set the focus on another control before clicking in the text box again. If you click the same place over an over, you only enter it the first time.