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

How to cycle through all TextBox in a Form ?

Hi all,
I need to highlight textbox in a Form when they are selected.
In order to do it I have added for each one a .GotFocus and .LostFocus
Event Handler....

textRS.GotFocus += new EventHandler(gotFocus_Event);
textName.GotFocus += new EventHandler(gotFocus_Event);
textSurname.GotFocus += new EventHandler(gotFocus_Event);
textAddress.GotFocus += new EventHandler(gotFocus_Event);

textRS.LostFocus += new EventHandler(lostFocus_Event);
textName.LostFocus += new EventHandler(lostFocus_Event);
textSurname.LostFocus += new EventHandler(lostFocus_Event);
textAddress.LostFocus += new EventHandler(lostFocus_Event);

I'd like to know how can I accomplish the same iterating through all
TextBoxes in the Form, so I can use this function in all Forms....
Thanks a lot
Francesco

Nov 16 '05 #1
4 4548
public void HookupTextBoxes(Control.ControlCollection controls) {
foreach(Control control in this.Controls) {
if(control is TextBox) {
TextBox textBox = (TextBox) control;
textBox.GotFocus += new EventHandler(gotFocus_Event);
textBox.LostFocus += new EventHandler(lostFocus_Event);
} else {
HookupTextBoxes(control.Controls);
}
}
}

MainForm ctor, after InitializeComponent:
HookupTextBoxes(this);

I think that should do it.

<fm********@libero.it> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Hi all,
I need to highlight textbox in a Form when they are selected.
In order to do it I have added for each one a .GotFocus and .LostFocus
Event Handler....

textRS.GotFocus += new EventHandler(gotFocus_Event);
textName.GotFocus += new EventHandler(gotFocus_Event);
textSurname.GotFocus += new EventHandler(gotFocus_Event);
textAddress.GotFocus += new EventHandler(gotFocus_Event);

textRS.LostFocus += new EventHandler(lostFocus_Event);
textName.LostFocus += new EventHandler(lostFocus_Event);
textSurname.LostFocus += new EventHandler(lostFocus_Event);
textAddress.LostFocus += new EventHandler(lostFocus_Event);

I'd like to know how can I accomplish the same iterating through all
TextBoxes in the Form, so I can use this function in all Forms....
Thanks a lot
Francesco

Nov 16 '05 #2
public void HookUpTextBoxes(Form frm)
{
foreach( Control c in frm.Controls)
{
TextBox t = c as TextBox;
if( t != null )
{
t.GotFocus += new EventHandler(gotFocus_Event);
t.LostFocus += new EventHandler(lostFocus_Event);
}
}
}

This doesn't cater for panels, etc which may contain textboxes, but you can special case things like that - or just recurse in general

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

Hi all,
I need to highlight textbox in a Form when they are selected.
In order to do it I have added for each one a .GotFocus and .LostFocus
Event Handler....

textRS.GotFocus += new EventHandler(gotFocus_Event);
textName.GotFocus += new EventHandler(gotFocus_Event);
textSurname.GotFocus += new EventHandler(gotFocus_Event);
textAddress.GotFocus += new EventHandler(gotFocus_Event);

textRS.LostFocus += new EventHandler(lostFocus_Event);
textName.LostFocus += new EventHandler(lostFocus_Event);
textSurname.LostFocus += new EventHandler(lostFocus_Event);
textAddress.LostFocus += new EventHandler(lostFocus_Event);

I'd like to know how can I accomplish the same iterating through all
TextBoxes in the Form, so I can use this function in all Forms....
Thanks a lot
Francesco
--
No virus found in this incoming message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.7.1 - Release Date: 19/01/2005

[microsoft.public.dotnet.languages.csharp]
Nov 16 '05 #3
Hah! Plagiarist! You stole the name of my function! ;D

--
Sean Hederman

http://codingsanity.blogspot.com

"Richard Blewett [DevelopMentor]" <ri******@NOSPAMdevelop.com> wrote in
message news:en**************@TK2MSFTNGP11.phx.gbl...
public void HookUpTextBoxes(Form frm)
{
foreach( Control c in frm.Controls)
{
TextBox t = c as TextBox;
if( t != null )
{
t.GotFocus += new EventHandler(gotFocus_Event);
t.LostFocus += new EventHandler(lostFocus_Event);
}
}
}

This doesn't cater for panels, etc which may contain textboxes, but you
can special case things like that - or just recurse in general

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

Hi all,
I need to highlight textbox in a Form when they are selected.
In order to do it I have added for each one a .GotFocus and .LostFocus
Event Handler....

textRS.GotFocus += new EventHandler(gotFocus_Event);
textName.GotFocus += new EventHandler(gotFocus_Event);
textSurname.GotFocus += new EventHandler(gotFocus_Event);
textAddress.GotFocus += new EventHandler(gotFocus_Event);

textRS.LostFocus += new EventHandler(lostFocus_Event);
textName.LostFocus += new EventHandler(lostFocus_Event);
textSurname.LostFocus += new EventHandler(lostFocus_Event);
textAddress.LostFocus += new EventHandler(lostFocus_Event);

I'd like to know how can I accomplish the same iterating through all
TextBoxes in the Form, so I can use this function in all Forms....
Thanks a lot
Francesco
--
No virus found in this incoming message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.7.1 - Release Date: 19/01/2005

[microsoft.public.dotnet.languages.csharp]

Nov 16 '05 #4
Thank you very much for your kind & quick answer.
Regards
Francesco

Nov 16 '05 #5

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

Similar topics

8
by: John Ortt | last post by:
Hi there, I have written the following code to colour cycle the background in one of my forms. The problem is it only cycles from Black to Red and then reverts back to Black. Does anyone...
4
by: Rodrigo DeJuana | last post by:
Howdy, I'm new to this .net stuff and really have little to no training. Im trying to create a new page for a web form, so i have been pretty much jsut coping code. I having some issue with...
28
by: kfrost | last post by:
I know this is probably simple but I have a C# form and the class for the form is called sbaSynch. I have a textbox name txtServerName. I'm creating a class to manipulate XML functions so I...
12
by: TB | last post by:
Hi All: I am trying to create a variation on the standard datagrid, whereby the datagrid is only shown after pressing some buttons. This reason for this is that I would like to use the same...
11
by: Keith | last post by:
I apologize for those of you who think I'm posting on the same topic. It is not that I don't appreciate all of your comments - and I'm definitely reading them all - but I think I have a differing...
5
by: Tosch | last post by:
I have a usercontrol with a label, a textbox, a treeview, a grid and a couple of checkboxes. The usercontrol is hosted on a form together with a cancel and a accept button. This form is used to...
3
by: DotNetNewbie | last post by:
I am reading the book Teach Yourself Microsoft Visual Basic .Net 2003 in 21 Days. I am having trouble getting one of the exercises to work at the end of day 4. Exercises: 1. Create a new...
1
by: Jon Paal | last post by:
I have a textbox in a form that saves information to a database. A linkbutton activates a function from the user's click to save the data. A leading string of text is added to the content before...
0
by: Jacob Donajkowski | last post by:
Once the user logs in I want to have the users switch from the Roster View to the Profile View and enter their profile infomation and save it. Then the next time they login and go to the Profile...
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
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
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
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...
0
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...
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,...

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.