Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Event Details 1

Status
Not open for further replies.

ice78991

Programmer
Nov 20, 2006
216
I am using the following code to run the same event handler function

this.numericUpDown_SizeY.ValueChanged += new System.EventHandler(this.numericUpDown_Sizey_ValueChanged);
this.numericUpDown_SizeY.KeyUp += new System.Windows.Forms.KeyEventHandler(this.numericUpDown_Sizey_ValueChanged);


private void numericUpDown_SizeY_ValueChanged(object sender, EventArgs e){

etc etc



Is it possible within numericUpDown_SizeY_ValueChanged to determine whether it has been called by the ValueChanged or the KeyUp handler. I need to know which.
 
im assuming the parameters for both events are (obect sender, EventArgs e) ?

If so, see if what is sent as the "sender" is of different types. That could be your clue as to which event was fired.
 
uhhhh KeyUp is a KeyEventHandler not an EventHandler soo....

point them at different methods and have those methods call an abstracted method.

Code:
his.numericUpDown_SizeY.ValueChanged += new System.EventHandler(this.numericUpDown_Sizey_ValueChanged);
            this.numericUpDown_SizeY.KeyUp += new System.Windows.Forms.KeyEventHandler(this.numericUpDown_Sizey_KeyUp);


private void DoYourStuffHere()
{
    //Doyourstuff
}

private void numericUpDown_Sizey_ValueChanged(object sender, EventArgs e)
{
    DoYourStuffHere();
}

private void numericUpDown_Sizey_KeyUp(object sender, KeyEventHandler e)
{
     DoYourStuffHere();
}
 
Like JurkMonkey says. Put the code that is the same in a shared private method. Put the code that is different in it's respective event handler.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top