473,406 Members | 2,619 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,406 software developers and data experts.

Giving a TextBox the Focus when the form comes up

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
Nov 15 '05 #1
4 2173
Try Form.Enter or Form.Activated events.

kuba florczyk

Użytkownik "Randy" <te**@temp.com> napisał w wiadomości
news:%2*****************@TK2MSFTNGP11.phx.gbl...
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

Nov 15 '05 #2
DM
Form.Activated event works but the problem is that this transfers focus to
textbox every time form gets activated.

I know we can keep a flag variable to check it.

Is there any other straight forward way to do this.

Thanks
"Kuba Florczyk" <ch******@poczta.onet.pl> wrote in message
news:Oj**************@TK2MSFTNGP09.phx.gbl...
Try Form.Enter or Form.Activated events.

kuba florczyk

Użytkownik "Randy" <te**@temp.com> napisał w wiadomooci
news:%2*****************@TK2MSFTNGP11.phx.gbl...
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


Nov 15 '05 #3
"Randy" <te**@temp.com> wrote in message
news:%2*****************@TK2MSFTNGP11.phx.gbl...
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?


textBox1.Focus() should work as long as it is *after* InitializeComponent().
Form_Load() is a good place for this. Focus() won't work though if the
textbox has .Enabled=false or .Visible=false.

If you're still having trouble please post a minimal code sample that
illustrates the problem.

-- Alan
Nov 15 '05 #4
Thanks, I didn't have the tab order set...I put the text box as the first on
the tab order and it works like I expected...thanks again..

"Alan Pretre" <no@spam> wrote in message
news:OZ**************@TK2MSFTNGP09.phx.gbl...
"Randy" <te**@temp.com> wrote in message
news:%2*****************@TK2MSFTNGP11.phx.gbl...
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?
textBox1.Focus() should work as long as it is *after*

InitializeComponent(). Form_Load() is a good place for this. Focus() won't work though if the
textbox has .Enabled=false or .Visible=false.

If you're still having trouble please post a minimal code sample that
illustrates the problem.

-- Alan

Nov 15 '05 #5

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

Similar topics

4
by: Albinas | last post by:
Hi all, I am trying to customize the text box to suit the practice of my app. And I am working about the focus behavior of text field. I have met the the following problem. When I set the...
2
by: JayDee | last post by:
After a user enters data into a field, I need to populate other controls on the form, based on the user entry. I have to use either Leave, Validating or Validated, and I take it I can't use...
0
by: Jonas L | last post by:
Hi, I need to create a textbox which acts as a normal textbox but with the following extra requirements: 1) In-focus color, when the textbox gets focus the backcolor property of the textbox...
0
by: Angel | last post by:
I have a Win application with two child windows (formX and formY) that are both opened when the application loads. formX has a multi-line textbox that I use to enter an address, and two button...
3
by: Jose Egea | last post by:
Hello: I'm trying to execute a function when the user press Enter key in a TextBox. But something is happening in my form because after pressing a button, when I press the Enter key in the...
2
by: Jesper | last post by:
Last week I posted this for the first time. However, I didn't get any useable solution to my problem. I'm very keen on getting this problem solved, so please excuse me for trying again. I'll try to...
10
by: tshad | last post by:
I have a page where I give focus to the first textbox on my page: <body onLoad="document.forms.firstName.focus();"> I also go and check the status of some data when I exit the 3rd textbox on...
5
by: Tosch | last post by:
I have a usercontrol with a label, a textbox, a treeview, a grid and a couple of checkboxes. The usercontrol is hosted on a form together with a cancel and a accept button. This form is used to...
5
by: =?Utf-8?B?QmVuIFIu?= | last post by:
Hi, In a .NET 2.0 winforms application, I've got a textbox that, when updated, uses the validated event to cascade the change to another textbox (along with another value). This works well if...
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: 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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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
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,...

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.