473,505 Members | 15,626 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to set focus to a text box on windows form load?

I want to set focus to a text box on a C# windows form when the form loads.
How can I do this? I want the cursor to be in this text box when the form
loads so the user can just start typing. Below is what I have so far:

private void County_Load(object sender, EventArgs e)
{
txtCounty.Focus();
}

Thanks for the help

Oct 30 '08 #1
4 40690
Do it in the show event

"Walter" <wa********@yahoo.comwrote in message
news:AD**********************************@microsof t.com...
>I want to set focus to a text box on a C# windows form when the form loads.
How can I do this? I want the cursor to be in this text box when the form
loads so the user can just start typing. Below is what I have so far:

private void County_Load(object sender, EventArgs e)
{
txtCounty.Focus();
}

Thanks for the help

Oct 30 '08 #2

Bear with me as I am new to C# (been a DBA for 10 years). How would I do
that in the show event? Thanks.
"Mel Weaver" <Me***********@Insdirect.comwrote in message
news:uc****************@TK2MSFTNGP05.phx.gbl...
Do it in the show event

"Walter" <wa********@yahoo.comwrote in message
news:AD**********************************@microsof t.com...
>>I want to set focus to a text box on a C# windows form when the form
loads. How can I do this? I want the cursor to be in this text box when
the form loads so the user can just start typing. Below is what I have so
far:

private void County_Load(object sender, EventArgs e)
{
txtCounty.Focus();
}

Thanks for the help

Oct 30 '08 #3
On Thu, 30 Oct 2008 12:50:03 -0700, Walter <wa********@yahoo.comwrote:
Bear with me as I am new to C# (been a DBA for 10 years). How would I
do that in the show event? Thanks.
The same way you've already done it for the Load event, except attach your
handler to the Show event instead.

That said, an alternative would be simply to set the TabIndex for the
TextBox to be the lowest TabIndex for the Form (typically, that would be
"0"). Then the framework will simply set the focus to that TextBox
automatically for you.

Pete
Oct 30 '08 #4
On Thu, 30 Oct 2008 13:10:21 -0700, Peter Duniho
<Np*********@nnowslpianmk.comwrote:
On Thu, 30 Oct 2008 12:50:03 -0700, Walter <wa********@yahoo.comwrote:
>Bear with me as I am new to C# (been a DBA for 10 years). How would I
do that in the show event? Thanks.

The same way you've already done it for the Load event, except attach
your handler to the Show event instead.
Er, make that the "Shown" event. Intellisense should make it easy to
figure that out, but just in case... :)
Oct 30 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2178
by: Randy | last post by:
Hello all, I have a form with a text field (textBox1) on it. Apparently, textBox1.Focus() doesn't work when the form is initializing. I put this in the Constructor and also in the Load event for...
2
2162
by: Miky | last post by:
Hi, I have the following problem: I have a .CFM web page and I have to populate, from VB, two textboxes on it. I was thinking using sendkeys (even if I don't like it too much) but when I...
8
1989
by: copyco | last post by:
I want to be able to test if my app's form has focus, (ie: not in background, behind other windows). How can I do this? I tried the Me.Focused, but that doesn't work. I think it's because a...
8
18618
by: Alison | last post by:
Hi, Al I am trying to design a user interface which provides both menus and toolbars for some users to click on whatever they want to do, at the same time, I would like to have a console window...
1
5209
by: vvenk | last post by:
Hello: I have a windows form that has a command button. I was trying to set focus on it in the form's Load event. It did not work. However, moving the line of code to the form's activate event,...
4
3130
by: Rod Gill | last post by:
Hi, I have a form that when opened in the designer appears of the screen. The form selector can't be dragged (or resized) and if I scroll right and down to centralise it the form simply jumps...
4
14956
by: sam | last post by:
hi, How to set constant focus on window form in c#. cheers Sam
2
2051
by: Jesper | last post by:
Hi, I have an C# windows application running that has the property WindowsState of the main form set to 'Minimized' and the property ShowInTaskBar set to false. I've asingned a notifyIcon to the...
6
3070
Megalog
by: Megalog | last post by:
Hey guys, my turn to ask a question =D Ok here's my situation.. I have a super simple form, which is bound to a table with a single record. All the controls (mostly text boxes, some true/false...
0
7098
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
7367
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...
1
7018
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5028
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4699
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3187
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1528
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.