Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
dear friends
i have a class like
C#
class1{
int id;
string name;
public System.Windows.Forms.Timer TimerObj = new System.Windows.Forms.Timer();
}


then create object

C#
class1 Obj = new class1();

Obj.id=1;
Obj.name="AA";
TimerObj.Interval = 1000;
Obj.TimerObj.Tick += new EventHandler(Timer_Tick);


and i want to access Obj in EventHandler

C#
private void Timer_Tick(object sender, EventArgs e)
{
// ??????  HOW I CAN ACCESS CLASS1 OBJ FROM SENDER
((Timer)sender).
}


thanks
Posted

1 solution

Try:
C#
    Obj.id=1;
    Obj.name="AA";
    TimerObj.Interval = 1000;
    TimerObj.Tag = Obj;
    Obj.TimerObj.Tick += new EventHandler(Timer_Tick);
    ...
private void Timer_Tick(object sender, EventArgs e)
    {
    Timer t = sender as Timer;
    if (t != null)
       {
       class1 c = t.Tag as class1;
       if (c != null)
          {
          ...
          }
       }
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900