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

Cause a Textbox to lose focus

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

Nov 17 '05 #1
2 19546
ch***@ckerrison.freeserve.co.uk wrote:
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.


Assuming your control derives from System.Windows.Forms.Control. Look at
calling the SelectNextControl method on the Form object that the instance of
your control is on in an override OnKeyPress. You can call your FindForm
method to get the form that your control is on.
--
Tom Porterfield
Nov 17 '05 #2
You can also call the Focus() method of a specific control, provided that
control's CanFocus property is true. Focus() returns a bool based on
success or failure; if CanFocus == false then Focus() will always return
false.

In my experience all "out of the box" WinForms controls will respond
correctly to Focus() even when the form hasn't been shown yet, but some
third party controls will not do this until the form is shown (specifically,
I've seen this with controls from Infragistics). So if you ever want to set
initial focus on a new form based on some condition or other, it's safest to
do that in the form's Activate event rather than in the Load event or from
somewhere outside the form before it's shown.

--Bob

"Tom Porterfield" <tp******@mvps.org> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
ch***@ckerrison.freeserve.co.uk wrote:
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.


Assuming your control derives from System.Windows.Forms.Control. Look at
calling the SelectNextControl method on the Form object that the instance
of your control is on in an override OnKeyPress. You can call your
FindForm method to get the form that your control is on.
--
Tom Porterfield

Nov 17 '05 #3

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

Similar topics

11
by: Junkguy | last post by:
I need some help programmatically causing a row in a DataGrid to "flush" its contents to its bound data (in Visual Studio 6 using Windows Forms with C#). My issue is I want to send an update to...
2
by: Alpha | last post by:
Hi, I have a window based program. One of the form has several textboxes and a datagrid. The textboxes are bind to the same dataset table as the datagrid and the text changes to reflect different...
10
by: mg | last post by:
I want to enter characters in a TextBox in a WebForm, press a Button in the WebForm, and read the characters that were typed into the TextBox from within the Button_Click event handler. The main...
4
by: Craig G | last post by:
i have the following code for validating a textbox once a page posts, but the problem i am having is that the TextChanged event won't fire next time if the user does not change the value again ...
2
by: ThunderMusic | last post by:
Hi, I have a form in which there are many <asp:textbox> tags. When I run the form, we use tab to navigate across the textboxes, but one of our client noticed that when we navigate to some readonly...
4
by: OpticTygre | last post by:
If I create a checkbox dynamically: Dim NewCheckBox as New Checkbox Then, I display that checkbox on a form, how can I cause the checkbox to lose focus after a user clicks on it? TIA, ...
3
by: Patrick [MSFT] | last post by:
Let me preface this with the goal I'm trying to achieve is mimic a feature of another language (Dexterity used by Microsoft Dynamics) and so while a filling a drop down list is a workable solution...
8
by: Mihai N. | last post by:
I need to format any decimal value so that it is right aligned, thousands It is good to show the info in the format the user prefers. That is language/locale speciffic (CultureInfo in the .NET...
10
by: engteng | last post by:
When textbox properties enable = False the font in the textbox become gray color. How do I change the gray color to black color ? Regards, Tee
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
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
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,...
0
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...

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.