How to identify Form.Control by sender

  • Thread starter Thread starter Jazer
  • Start date Start date
J

Jazer

private void ValidationEvent(object sender, CancelEventArgs e)
{
if <...>{
this.errorMsg.SetError( sender, "Error");}
//error: /\
}

How to do indentify control by sender?

Form.ActiveControl points to next control.
 
You just need to cast it to a control:
(Control)sender;

eg:
string name = ((Control)sender).Name;

to get its name.

- Mark
 
Thank you.
(sender as Control) could be too.
Mark Harris said:
You just need to cast it to a control:
(Control)sender;

eg:
string name = ((Control)sender).Name;

to get its name.

- Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top