473,503 Members | 1,929 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Setting focus on a control when the form is loaded

Hi, there!

I want to set focus on a control, of which TabIndex is not the first, when a
form is loaded. In the form's load event, I have used Control.Focus() but it
doesn't not work. The focus is not on the control I set. The focus is always
on the control of which TabIndex is 0.

Thanks.
Nov 21 '05 #1
4 1908
If you always want the same control to be given focus when the form loads,
the best (and easiest) way would be to use JavaScript. To do this, simply
add the following to you Body tag:

OnLoad="mycontrol.focus();"

--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"Aung Thu" <Au*****@discussions.microsoft.com> wrote in message
news:ED**********************************@microsof t.com...
Hi, there!

I want to set focus on a control, of which TabIndex is not the first, when
a
form is loaded. In the form's load event, I have used Control.Focus() but
it
doesn't not work. The focus is not on the control I set. The focus is
always
on the control of which TabIndex is 0.

Thanks.

Nov 21 '05 #2
Thanks, Nathan.

Sorry, I forgot to mention about my application. It is Windows application,
not Web Form.

Base on the different condition, I need to set the initial focus on the
specific control when the form is loaded. So I tried the ControlName.Focus()
in the Load event of the form. But it doesn't work. How should I do to get it?

Thanks.

"Nathan Sokalski" wrote:
If you always want the same control to be given focus when the form loads,
the best (and easiest) way would be to use JavaScript. To do this, simply
add the following to you Body tag:

OnLoad="mycontrol.focus();"

--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"Aung Thu" <Au*****@discussions.microsoft.com> wrote in message
news:ED**********************************@microsof t.com...
Hi, there!

I want to set focus on a control, of which TabIndex is not the first, when
a
form is loaded. In the form's load event, I have used Control.Focus() but
it
doesn't not work. The focus is not on the control I set. The focus is
always
on the control of which TabIndex is 0.

Thanks.


Nov 21 '05 #3
Aung,

Did you try it in the activated event of the form?

I hope this helps,

Cor
Nov 21 '05 #4
"Aung Thu" <Au*****@discussions.microsoft.com> schrieb:
I want to set focus on a control, of which TabIndex is not the first, when
a
form is loaded. In the form's load event, I have used Control.Focus() but
it
doesn't not work. The focus is not on the control I set. The focus is
always
on the control of which TabIndex is 0.


\\\
Private Sub Form1_Activated( _
ByVal sender As Object, _
ByVal e As EventArgs _
) Handles MyBase.Activated
Static IsActivated As Boolean
If Not IsActivated Then
IsActivated = True
Application.DoEvents() ' ...
Me.TextBox1.Focus()
End If
End Sub
///

In .NET 2.0 Windows Forms forms have a 'Shown' event.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #5

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

Similar topics

2
3630
by: MLH | last post by:
A form named frmVehicleEntryForm has a number of textbox controls who's OnGotFocus property setting is an expression... =Change2Green() Change2Green() looks something like this... Dim MyControl...
1
1883
by: Jason | last post by:
I have created a c-sharp app that has keyup, keydown events tied to the form. The form also has some other controls, buttons, labels and 1 custom control that I made which inherits from user...
1
1292
by: Abhram Jose | last post by:
I have a edit box in my web form. When the form is loaded I want to set the focus on this control. How to do that ? Thanks Abhram Jose
12
4867
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...
18
1198
by: Charles May | last post by:
I know I've done this somewhere but I cannot find any example of it in any of my test code. I have a form with a Listbox that is filled by a dataset it fills in various textboxes. When the...
1
2029
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...
3
2134
by: DJTN | last post by:
I have an IE web control on a form that rotates the stats of the call center in it. When a new page is loaded it takes the focus away from the other textboxes on the form, even if a user is typing...
7
8037
by: Zytan | last post by:
I want to set a control in a form to have the default focus. This is not the accept button -- that's set to a button when is 'clicked' when you press ENTER. I want a textbox to have the focus...
3
2426
by: zacks | last post by:
I am working on an application that has a UI that supports multiuple functions by means of a group of "plug ins". Each plugin is a class library. Each plugin contains a User Control that defines...
0
7192
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
7064
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
7261
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,...
1
6974
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
5559
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,...
0
4665
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
3158
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
3147
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.