473,732 Members | 2,205 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 1925
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="mycontr ol.focus();"

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

"Aung Thu" <Au*****@discus sions.microsoft .com> wrote in message
news:ED******** *************** ***********@mic rosoft.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.Foc us()
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="mycontr ol.focus();"

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

"Aung Thu" <Au*****@discus sions.microsoft .com> wrote in message
news:ED******** *************** ***********@mic rosoft.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*****@discus sions.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.Activate d
Static IsActivated As Boolean
If Not IsActivated Then
IsActivated = True
Application.DoE vents() ' ...
Me.TextBox1.Foc us()
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
3657
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 As Control Set MyControl = Screen.ActiveControl MyControl.BackColor = 65280 Tabbing from control-to-control is great. Each time I land on
1
1898
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 control. My problem is ... When I first start the app all my keyboard events work fine and by doing debugging I can see that my form has the focus. After I click on a button or my custom control the focus is shifted to those controls and the keyup,...
1
1300
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
4904
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 cmdButton1_Clicked() { document.all('txtInput1').focus(); return false; }
18
1213
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 form first opens, I have to tab to the listbox so that I can scroll down the list. How do I setfocus to the listbox (I know I can change the tab order but I
1
2061
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 for the two steps, TextBox1.Text ="foo"; and TextBox2.Text = "bar";
3
2144
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 in them. Is there anyway to keep the control from getting focus?
7
8062
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 when the form is loaded. The textbox cannot be the first in the Tab order, since it's not at the top of the window, and it seems silly to start the tab order at it just to fix this issue. I cannot call control.Focus() from Form1_Load() since...
3
2436
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 the controls for that plugin's main form. The UI has a PictureBox control that is nothing but a contain to add the UserControl from the selected plugin, so that when the user selects a plugin, the main form changes appearance to the UserControl in...
0
8946
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9307
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
9235
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
9181
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6031
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4550
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3261
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
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
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.