Setting focus for a textbox

G

Guest

Hi,

I'm showing a usercontrol containing a textbox on the screen by clicking a
notifyIcon in the taskpane.

I use textBox.Focus() to set the focus for the texbox, and I also get a
blinking text cursor in the textbox. However. I have to click on the
usercontrol before it gets the input so that I can type text in the textbox.
I would really much like to be able to wirte in the textbox immediately after
clicking the notify icon. I've tryed to set the focus to the user control
also, but this doesn't help. Any suggestions.

code snippet:

private void notifyIcon1_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
if (e.Button == MouseButtons.Left )
{
FormShortcut form = new FormShortcut();
form.tb_proj.Focus();
form.Show();
}
else
{
System.Environment.Exit( System.Environment.ExitCode );
}
}
 
G

Guest

What about setting focus to the textbox inside of an overridden OnGotFocus
method within your UserControl?

Brendan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top