473,242 Members | 1,493 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,242 software developers and data experts.

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 1897
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
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
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
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
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
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
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
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
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
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
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.