Steven Du
Steven Du

Reputation: 1691

Disable event of Inherited UserControl

(Hi, all)

I have create a new user control inherit from tabcontrol, and override few events.

When I switch from one tabpage to another, the following event are fired in sequence:

1) OnDeselecting(TabControlCancelEventArgs e)
2) OnMouseDown(MouseEventArgs e)
3) OnMouseClick(MouseEventArgs e)
4) OnMouseUp(MouseEventArgs e)

How could I temporally disable 2) and 3) when 1) is fired?

Your help will be greatly appreciated!

PS:

I do need all of these events, and currently I am using a bool variable to do the dirty job.

.net 3.5+ VS2008+ Win7 64

Upvotes: 0

Views: 503

Answers (1)

Steve
Steve

Reputation: 216293

Try this in your OnDeselecting Event

try
{
    tab.MouseDown -= new MouseEventHandler(this.YourMouseDownEvent);
    tab.MouseClick -= new MouseEventHandler(this.YourMouseClickEvent);
    ..... // your code here.....
}
finally
{
    tab.MouseDown += new MouseEventHandler(this.YourMouseDownEvent);
    tab.MouseClick += new MouseEventHandler(this.YourMouseClickEvent);
}

Upvotes: 2

Related Questions