new event

  • Thread starter Thread starter Ian
  • Start date Start date
I

Ian

Hi,
I intherited Button and I created new class (myButton)

public class myButton: System.Windows.Button
{
....
}

I want declare new event. (BeforeClick) This event runs before Buttons click
event. In some case in this event, click event doesn't run.

For example;

(in BeforeClick event)
if button.text = 'bla bla'
DontRunClickEvent
else
RunClickEvent;

"Sory for bad English"
 
Ian said:
Hi,
I intherited Button and I created new class (myButton)

public class myButton: System.Windows.Button
{
...
}

I want declare new event. (BeforeClick) This event runs before Buttons click
event. In some case in this event, click event doesn't run.

For example;

(in BeforeClick event)
if button.text = 'bla bla'
DontRunClickEvent
else
RunClickEvent;

"Sory for bad English"

protected override OnClick(EventArgs e)
{
if (Text=="bla bla")
{
// Whatever
}
else
{
base.OnClick(e);
}
}
 
Ian said:
this code is not hardcoded. User can write their control code in
OnBeforeClick event and they can prevent to run onclick event.

Then you need to work that part out separately - that's a different
question which requires any amount of different information. The code I
gave you should help you only fire the event when you want to though.
 
Hi Ian,

So you want a similar functionality that the Closing/Close events of the
form

What you can do is extend EventArgs to include a property like
ContinueToClick and that the delegate called in the BeforeClick event set
according.
Then in OnBeforeEdit method you assign the value to an instance variable
that you check in the onClick event .


Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

Ian said:
Hi Jon,
if (Text=="bla bla")

this code is not hardcoded. User can write their control code in
OnBeforeClick event and they can prevent to run onclick event.
 
Back
Top