473,595 Members | 2,442 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Set focus on a specified control

How can I set the focus on a specified control in a Windows form ?
Thank you.
Gilbert
Nov 21 '05 #1
8 1067
Simply:

[Control Name].Select

e.g. TextBox1.Select

Hope this helps.
"Gilbert Tordeur" <gi************ *@fr.york.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
How can I set the focus on a specified control in a Windows form ?
Thank you.
Gilbert

Nov 21 '05 #2
[yourcontrol].Focus( )
eg. TextBox1.Focus( ), etc

you can check the return value to determine whether the focus was set
successfully or not.
true if successful; false otherwise.

hope this helps..
Imran.

"Gilbert Tordeur" <gi************ *@fr.york.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
How can I set the focus on a specified control in a Windows form ?
Thank you.
Gilbert

Nov 21 '05 #3
M
What about textbox1.Focus( )

"Matt S" <ma**@toomuchsp amalready.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Simply:

[Control Name].Select

e.g. TextBox1.Select

Hope this helps.
"Gilbert Tordeur" <gi************ *@fr.york.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
How can I set the focus on a specified control in a Windows form ?
Thank you.
Gilbert


Nov 21 '05 #4
* "Gilbert Tordeur" <gi************ *@fr.york.com> scripsit:
How can I set the focus on a specified control in a Windows form ?


In addition to the other replies: Notice that the focus can only be set
to a visible and enabled control.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #5
"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:O6******** *****@TK2MSFTNG P11.phx.gbl...
* "Gilbert Tordeur" <gi************ *@fr.york.com> scripsit:
How can I set the focus on a specified control in a Windows form ?


In addition to the other replies: Notice that the focus can only be set
to a visible and enabled control.


Ugh! This is SO important. I wasted a whole day not being able to figure out
why button1.Perform Click() wasn't working. Turns out it will only work IF
the button is enabled. BTW, is there a way to execute the sub if the button
IS NOT enabled? It's no big deal to check it's status, enable it if off, and
disable it again later (well, it is kind of a pain) but it would be nice to
be able to override it without worrying about it's status and making sure
it's returned to it's previous state.
Nov 21 '05 #6
Ricky,

Until now I did not know this problem, however a lot of people are just
calling the sub.

The performclick does something as
button1_click(n othing,nothing)

What is found by some active in this newsgroup awful, however the only
reason I can think about that it looks very awful (what I find as well)

:-)

Cor
Nov 21 '05 #7
"Cor Ligthert" <no**********@p lanet.nl> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Ricky,

Until now I did not know this problem, however a lot of people are just
calling the sub.

The performclick does something as
button1_click(n othing,nothing)


Ah. I knew it was just a subroutine but I couldn't figure out how to call it
with the correct signature. So I can pass it Nothing as the arguments and it
won't choke (as long as I don't try to do anything with what is normally in
those arguments)? Sweet.
Nov 21 '05 #8
* "Ricky W. Hunt" <rh*****@hotmai l.com> scripsit:
How can I set the focus on a specified control in a Windows form ?


In addition to the other replies: Notice that the focus can only be set
to a visible and enabled control.


Ugh! This is SO important. I wasted a whole day not being able to figure out
why button1.Perform Click() wasn't working. Turns out it will only work IF
the button is enabled. BTW, is there a way to execute the sub if the button
IS NOT enabled? It's no big deal to check it's status, enable it if off, and
disable it again later (well, it is kind of a pain) but it would be nice to
be able to override it without worrying about it's status and making sure
it's returned to it's previous state.


I would take the code from the button's 'Click' event handler and place
it in a separate method. Then you can call this method from within the
'Click' event handler and from the place where you want the method to be
executed.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #9

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

Similar topics

5
11368
by: tshad | last post by:
I have a date validation function that I want to stay at the object I am validating if there is a Validation error, but it always goes to the next object. The Javascript: function ValidateForm(me){ var dt=me if (isDate(dt.value)==false){ dt.focus()
7
4459
by: Gerry Abbott | last post by:
Hi all, Ive got a form with several controls which contain date fields. I'm usng the activex calender control as a separate floating form, I would like to be able to click onto any of the date fields and use the calender to drop a date into it. So far, I've managed to drop the date selected from the calener, into a specified control, and requery the control to display the newly added date. Works fine using the rs object.
5
9434
by: Vinny Vin | last post by:
I would like to display a ToolTip (WinForms) when the Control associated recieves focus (when the control.enter event is triggered) as oppose to having the ToolTip displayed when the mouse hovers over the control,How can this be accomplished(Im developing in C#)?
4
1313
by: starbuck | last post by:
We have some fields with AutoPostBack set to true and when user tabs to the next field the screen re-calculates correctly however we also lose which control/text box had focus when the user tabbed. Is there any way of storing and resting which control should have focus? We are using asp.net with vb.net for code. Thanks ---
3
1178
by: A.M | last post by:
Hi, Can I configure a TextBox to have focus and cursor on it when page gets loaded? Thanks, Alan
4
4799
by: Kent P. Iler | last post by:
Hi, I am showing/hiding a variety of panels that have different text boxes via code-behind functions. Depending on the condition, I would like to have the focus be set on a specific text box. However, all examples I've seen do this from the client side. Does anyone have a way to easily to specify the textbox to focus on from a code-behind function? My guess is it will have to be some combination of server-side and client-side...
4
6627
by: Jon Slaughter | last post by:
Is there any method to temporarily disable focus changing?(I assume only method is tab or mouse?) This problem has been tieing me up for a while and nothing seems to work. The only thing that I *know* will work is to disable all tab stops on all controls. This brute force method doesn't seem like a good idea though. What I wanted to do was take control the control enter/leave and mouse enter/leave and "switch back" the focus when it is...
7
8047
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...
4
4041
by: Jason | last post by:
Hi, Here's the scenario: I have a web application that has window A and window B. A user has both window A and B open - window A is in the foreground and window B is behind it. If the user looking at window A clicks the "open window B" link, I want
0
7957
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
7883
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8262
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
8379
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
8020
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
5421
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
3875
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
2391
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
0
1226
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.