Simon Bennetts

Simon Bennetts

  • NA
  • 3
  • 1.2k

Lookup constants based on object names

Jan 28 2014 10:57 AM
Hi,
 
I have a windows application which places default / help values in empty text boxes on the form in gray to show the user what is supposed to be entered (e.g. FORENAME in my txtForename textbox) in the textbox.
 
I have a generic event for all my textboxes on Enter to remove the text, change back from gray and add the change event.  On exit, I'm checking if they've entered anything and would like to refill the textbox with it's default value if they've left it blank or delete it later.
 
I have a ParametersDefaults class which contains a list of constants with the same name as the text box objects (e.g. public const string txtForename = "FORENAME").
 
What I want to do is get that string value based on the sender object (which will always be a text box).
 
Something along the lines of
((TextBox)sender).Text = DefaultParameters.[sender.Name bit goes here!]
 
I'm sure there must be an easy way but I can't figure it out and it's only Tuesday!
 
Thanks in advance
Simon

Answers (2)