By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,358 Members | 2,957 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,358 IT Pros & Developers. It's quick & easy.

Setting focus for a textbox

P: n/a
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 );
}
}
Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
What about setting focus to the textbox inside of an overridden OnGotFocus
method within your UserControl?

Brendan
"Jesper" wrote:
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 );
}
}

Nov 17 '05 #2

P: n/a
You are setting focus BEFORE you show the form, do it the other way around.

--
Of all words of tongue and pen, the saddest are: "It might have been"

Bill.Richards @ greyskin .co .uk
http://greyskin.co.uk
"Jesper" wrote:
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 );
}
}

Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.