473,657 Members | 2,504 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cannot set focus to an object in the form load event?

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?

Venkat
Nov 21 '05 #1
1 5214
"vvenk" <vv***@discussi ons.microsoft.c om> schrieb:
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?


The focus can only be set to a control that is (1) visible and (2) enabled.
In the form's 'Load' event, the form is not yet visible and thus setting the
focus doesn't take effect.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #2

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

Similar topics

0
5070
by: Miquel | last post by:
Hi all. I felt frustrated when developing an 'UserControl' derivated from textBox, because sequence event (and Validate event) seems to fail. I Always thought my code was wrong. But after trying the UserControl a lot of hours I have the feeling that c# (or .Net) fails. Thus, I have developed a simple program with 3 textBox, 1 Botton and 1 ListBox (for showing results) which fire OnEnter, OnGotFocus,
2
19586
by: chris | last post by:
Does anybody know how I can programmatically cause a textbox to lose focus and automatically jump to the next appropriate control. I have a custom textbox usercontrol whereby the requirement is to enable the user to jump around between controls by hitting the enter key instead of tab key or mouse. Thanks
4
3944
by: SJ | last post by:
Hi all, I have come across a weird problem when attempting to automatically set the focus in a vb.net form to a checkbox control... In my form I have (on a tab page in a tab control) several textboxes and a checkbox. The behaviour I want from my app is as follows:- When the textbox (which is prior in tab order to the tab control) has been filled with a certain length of text by the user, the focus is
2
1576
by: Jack Russell | last post by:
I have a form containing a tab control I want focus set to a particular text box when the form opens. However doing this in the load form event If TabControl1.SelectedIndex = 0 Then If txtFileName.CanFocus Then txtFileName.Focus() End If End If
1
6348
by: mongphong28 | last post by:
Hi, I'm using a treeview as a menu, and when the user clicks on a node I want the focus to set to a control (ie textbox) in a panel to the right. The problem I'm having is the focus will not stay on the control, but instead jumps back to the treeview. I'm setting the focus in the AfterSelect event of the treeview, and if I step through the code the desired control does have .Focused = True after I have set it, but then somewhere after...
5
2036
by: Finn Stampe Mikkelsen | last post by:
Hi How can i set a focus to a textbox in my codebehind page?? I have this WebForm, that takes information from a user and 2 buttons on the form. One that takes action on the entered information and one that resets the form... The second on, the reset button, i would like to set focus back to the first textbox on the form. I already have an onload in my body, which sets the
9
18003
by: Zytan | last post by:
http://msdn2.microsoft.com/en-us/system.windows.forms.control.focus(VS.80).aspx this page says: "Focus is a low-level method intended primarily for custom control authors. Instead, application programmers should use the Select method or the ActiveControl property for child controls, or the Activate method for forms." I am trying to give a Numeric UpDown control focus. Only Focus() works. But this says to not use it.
8
6896
by: Mel | last post by:
I have several text boxes and drop-down lists in an AJAX Update Panel. All user inputs have the Postback property set to True. After I type something in the first input entry and press the "Tab" key how can I set the focus to the next box after the postback? Please help! Using Visual Studio 2005 Pro, Asp.net 2.0, vb.net, WinXP
3
1972
by: Christian Blackburn | last post by:
Hi Gang, I have two text boxes on a form and if the first text box is populated, I want to place focus on the second text box at startup. However, this never seems to work. What am I doing wrong here? private void frmMain_Activate(object sender, EventArgs e) { if (txtOne.Text != "") {
0
8844
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
8742
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
8518
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
8621
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
7354
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
6177
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...
0
4173
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...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1971
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.