473,386 Members | 2,050 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,386 software developers and data experts.

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 1052
Simply:

[Control Name].Select

e.g. TextBox1.Select

Hope this helps.
"Gilbert Tordeur" <gi*************@fr.york.com> wrote in message
news:%2****************@TK2MSFTNGP09.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****************@TK2MSFTNGP09.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**@toomuchspamalready.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Simply:

[Control Name].Select

e.g. TextBox1.Select

Hope this helps.
"Gilbert Tordeur" <gi*************@fr.york.com> wrote in message
news:%2****************@TK2MSFTNGP09.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*************@TK2MSFTNGP11.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.PerformClick() 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(nothing,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**********@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP10.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(nothing,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*****@hotmail.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.PerformClick() 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
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...
7
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...
5
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...
4
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....
3
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
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. ...
4
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...
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...
4
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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,...
0
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...

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.