473,657 Members | 2,355 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(obj ect sender, EventArgs e)
{
txtCounty.Focus ();
}

Thanks for the help

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

"Walter" <wa********@yah oo.comwrote in message
news:AD******** *************** ***********@mic rosoft.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(obj ect 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.comwr ote in message
news:uc******** ********@TK2MSF TNGP05.phx.gbl. ..
Do it in the show event

"Walter" <wa********@yah oo.comwrote in message
news:AD******** *************** ***********@mic rosoft.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(obj ect sender, EventArgs e)
{
txtCounty.Focus ();
}

Thanks for the help

Oct 30 '08 #3
On Thu, 30 Oct 2008 12:50:03 -0700, Walter <wa********@yah oo.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*********@nn owslpianmk.comw rote:
On Thu, 30 Oct 2008 12:50:03 -0700, Walter <wa********@yah oo.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
2184
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 the form. textBox1 still doesn't get the focus when the form comes up. How do you do this? Thanks
2
2175
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 open the web browser and navigate to the selected page, I cannot set the focus to the html part of the control (only the web control takes the focus) so I can't use sendkeys to populate the fields I need.
8
2001
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 control within the form actually has focus, so the Me.Focused would return false. Thanks!
8
18638
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 available in the same form for users to enter commands and display outputs if some prefer to use character based user interface. I would like to implement the user interface in vb .net. Now I have menus and toolbars ready, but do not now how to get a...
1
5214
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, it does. Any reason? Are there any other nuances about when to use the FormLoad and FormActivate events, like when and more importantly when not to use these events?
4
3147
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 further away, completely leaving the selector box area. Any ideas? VS 2003 and VB.Net This is a simple application at the moment but the form is inherited from a
4
14972
by: sam | last post by:
hi, How to set constant focus on window form in c#. cheers Sam
2
2062
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 form that is show next to clock in the lower rigth corner. When you click this notifyicon, I bring up a new form (form2) with a textbox on it. I've set the textbox to TabIndex = 1, and a blinking curson in the textbox shows that the textbox has...
6
3074
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 checkboxes and combos) are bound straight to each field. Now, in the table itself, each field has it's Description property filled out, instructing the user as to what data belongs in the field. I can pull this data on the form by using each...
0
8312
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8827
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8504
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7337
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6169
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
2732
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 we have to send another system
2
1959
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1622
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.