Click here to Skip to main content
16,004,969 members
Home / Discussions / C#
   

C#

 
AnswerRe: Retrieve the control's name Pin
c0ax_lx27-Nov-09 23:34
c0ax_lx27-Nov-09 23:34 
GeneralRe: Retrieve the control's name [modified] Pin
Luc Pattyn28-Nov-09 0:54
sitebuilderLuc Pattyn28-Nov-09 0:54 
QuestionRe: Retrieve the control's name Pin
c0ax_lx28-Nov-09 1:07
c0ax_lx28-Nov-09 1:07 
AnswerRe: Retrieve the control's name Pin
Luc Pattyn28-Nov-09 1:20
sitebuilderLuc Pattyn28-Nov-09 1:20 
GeneralRe: Retrieve the control's name Pin
c0ax_lx28-Nov-09 1:31
c0ax_lx28-Nov-09 1:31 
GeneralRe: Retrieve the control's name Pin
PIEBALDconsult28-Nov-09 4:59
mvePIEBALDconsult28-Nov-09 4:59 
GeneralRe: Retrieve the control's name Pin
Luc Pattyn28-Nov-09 6:00
sitebuilderLuc Pattyn28-Nov-09 6:00 
AnswerRe: Retrieve the control's name Pin
BillWoodruff28-Nov-09 6:22
professionalBillWoodruff28-Nov-09 6:22 
Some ideas that may (I hope) bear on your solution :

Is it the case that any TextBoxes are inside containers within the Form (nested) : in that case you are going to need to recurse to find them and attach an Event Handler.

Unfortunately to get the Form.ControlCollection into a "flattened" IEnumerable where you can do cool filtering with Linq, and just, for example, pull out all the TextBoxes into a nice List<>, takes some voodoo which I am just now exploring myself, so am reluctant to comment on that so far.

If TextBoxes are the only controls you want to put a special Event handler on, it seems like overkill to add a subscriber to the 'Click event of every control on your Form or whatever (unless, of course, they are all TextBoxes).

foreach (Control candidate in Controls)
{
    if(candidate is TextBox) // assign your event handler here
}


The TextBox does expose an 'Enter event, and when that event is fired, you can be sure that the 'sender parameter inside that event is also the same as your MainForm.ActiveControl. That might be something you could exploit.

If you are maintaining an arbitrary collection of TextBox controls which the end-user has the power to create and/or remove, you might consider keeping a List<TextBox> up to date, and, possibly a TextBox currentTextBox variable: these may come in handy.

Assuming by "apply different rules to TextBoxes" you mean execute some code for one class of TextBoxes, and execute different code another class of TextBox you could consider a Dictionary of <TextBox, Action<Control>> as found in the very interesting answer by Nathan W. here : [^] which uses recursion in a very clever way.

best, Bill

"Many : not conversant with mathematical studies, imagine that because it [the Analytical Engine] is to give results in numerical notation, its processes must consequently be arithmetical, numerical, rather than algebraical and analytical. This is an error. The engine can arrange and combine numerical quantities as if they were letters or any other general symbols; and it fact it might bring out its results in algebraical notation, were provisions made accordingly." Ada, Countess Lovelace, 1844

QuestionDirectory Security Pin
ziwez027-Nov-09 22:01
ziwez027-Nov-09 22:01 
AnswerRe: Directory Security [modified] Pin
Saksida Bojan27-Nov-09 23:15
Saksida Bojan27-Nov-09 23:15 
Questionprivate methods using .net reflection. why?? Pin
mittalpa27-Nov-09 19:16
mittalpa27-Nov-09 19:16 
GeneralRe: private methods using .net reflection. why?? Pin
harold aptroot28-Nov-09 5:30
harold aptroot28-Nov-09 5:30 
QuestionSetup for published app crashes Pin
Charlesh327-Nov-09 19:14
Charlesh327-Nov-09 19:14 
AnswerRe: Setup for published app crashes Pin
Saksida Bojan27-Nov-09 20:55
Saksida Bojan27-Nov-09 20:55 
GeneralRe: Setup for published app crashes Pin
Charlesh328-Nov-09 5:05
Charlesh328-Nov-09 5:05 
QuestionGetting Error In For each Pin
Anubhava Dimri27-Nov-09 19:01
Anubhava Dimri27-Nov-09 19:01 
AnswerRe: Getting Error In For each Pin
Shameel27-Nov-09 20:03
professionalShameel27-Nov-09 20:03 
GeneralRe: Getting Error In For each Pin
Anubhava Dimri27-Nov-09 20:08
Anubhava Dimri27-Nov-09 20:08 
GeneralRe: Getting Error In For each Pin
Shameel27-Nov-09 20:10
professionalShameel27-Nov-09 20:10 
AnswerRe: Getting Error In For each Pin
Saksida Bojan27-Nov-09 20:29
Saksida Bojan27-Nov-09 20:29 
GeneralRe: Getting Error In For each Pin
Anubhava Dimri27-Nov-09 20:38
Anubhava Dimri27-Nov-09 20:38 
GeneralRe: Getting Error In For each Pin
Saksida Bojan27-Nov-09 21:10
Saksida Bojan27-Nov-09 21:10 
GeneralRe: Getting Error In For each Pin
Anubhava Dimri27-Nov-09 22:03
Anubhava Dimri27-Nov-09 22:03 
QuestionTextBox DataBindings doesn't work... Pin
shayke2327-Nov-09 14:37
shayke2327-Nov-09 14:37 
AnswerRe: TextBox DataBindings doesn't work... Pin
Christian Graus27-Nov-09 16:11
protectorChristian Graus27-Nov-09 16:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.