Can I determine the control that called a sub?

A

Academia

Within a sub can I determine the control that called it.

I can add a parameter to the sub so that I call it:

MySub(This, ...

But I'd rather not.



Is there some way to determine the caller within the sub?





Thanks in advance
 
P

Paul E Collins

Academia said:
Within a sub can I determine the control that called it.

If it's an event handler, then the first parameter "object sender" is
that control; just cast it to the appropriate type, e.g.

void button1_Click(object sender, EventArgs e)
{
Button b = (Button) sender;
}

Otherwise, no, you can't.

Eq.
 
A

Academia

I was hoping StackTrace or Reflections, which I know nothing about, would
work.


Thanks.
 

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

Top