J
Jay
I'm using VS 2005 C# Express.
I have an event handler that is called when the text cursor leaves one of many different text boxes.
When this is called, I want the text colour in that text box to change to Red. I assume that the
"sender" argument in the call is the text box that triggered the event. When I tried to change the
text colour using sender.ForeColor = System.Drawing.Color.Red; I get a compile error: 'object' does
not contain a definition for 'BackColor'. This didn't surprise me since I'm a C# beginner. Is there
some sort of cast I can use to make it work, or do I have to use if... else if... etc statements to
check for each of the text boxes that might have triggered the event (eg one is called tbxFbeg)?
Here's a fragment of my code...
private void tbxSettingsSa_Leave(object sender, EventArgs e){
sender.ForeColor = System.Drawing.Color.Red; //get compile error: 'object' does not contain a
definition for 'BackColor'
// sender is a textbox. The following line works OK...
// tbxFbeg.ForeColor = System.Drawing.Color.Red;
}
I have an event handler that is called when the text cursor leaves one of many different text boxes.
When this is called, I want the text colour in that text box to change to Red. I assume that the
"sender" argument in the call is the text box that triggered the event. When I tried to change the
text colour using sender.ForeColor = System.Drawing.Color.Red; I get a compile error: 'object' does
not contain a definition for 'BackColor'. This didn't surprise me since I'm a C# beginner. Is there
some sort of cast I can use to make it work, or do I have to use if... else if... etc statements to
check for each of the text boxes that might have triggered the event (eg one is called tbxFbeg)?
Here's a fragment of my code...
private void tbxSettingsSa_Leave(object sender, EventArgs e){
sender.ForeColor = System.Drawing.Color.Red; //get compile error: 'object' does not contain a
definition for 'BackColor'
// sender is a textbox. The following line works OK...
// tbxFbeg.ForeColor = System.Drawing.Color.Red;
}