473,386 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Setting focus for a textbox

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
2 14625
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jesper Dannemamm | last post by:
Hi I am having trouble setting focus on I tried using this script in the usercontrol's page_load sub to set focus on a textbox with the ID = "user_name": Page.RegisterStartupScript("focus",...
1
by: Rachel Suddeth | last post by:
I have an form where the whole display is a tab control (well, that plus a status bar.) I want to set the focus to the first TextBox on the first TabPage when it loads. I tried to put that into...
12
by: CLEAR-RCIC | last post by:
Hi, I'm having problems setting focus to a textbox on a web user contol on an asp.net web page. The following script works on normal asp.net pages: <script language="javascript"> function...
4
by: SJ | last post by:
Hi all, I have come across a weird problem when attempting to automatically set the focus in a vb.net form to a checkbox control... In my form I have (on a tab page in a tab control) several...
2
by: Sridhar | last post by:
Hi, I have a question. I have created a user control which contains a textbox and a button. we will enter some search word in the textbox and hit the button. Then we will get a pop-up with the...
1
by: clickon | last post by:
For testing purposes i have got a 2 step WizardControl. Eqach step contains a text box, TextBox1 and TextBox2 respectively. If i put the following code in the respective activate event handlers...
1
by: Praveena.Alapati | last post by:
Hi, There is a tab control on a page with multiple tabs and handful of controls in each tab. The way it's rendered in html (like grid etc..) is in table format in tablerows and cells. On...
5
by: Finn Stampe Mikkelsen | last post by:
Hi How can i set a focus to a textbox in my codebehind page?? I have this WebForm, that takes information from a user and 2 buttons on the form. One that takes action on the entered...
3
by: jp2express | last post by:
I have several applications that use panels as screens, but I can *not* seem to set the focus for a Textbox. Panel1.BringToFront() Panel1_Textbox.Focus() ' do something with a control on Panel1...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.