Link to home
Create AccountLog in
Avatar of jetbet
jetbetFlag for New Zealand

asked on

Overriding custom button behaviour

I have a form with a Custom button on it. This button has tool strips attached.
I want to override the behaviour of the toolstrip click method on the user control it is on, but although my code gets called I cannot stop the original code being called afterwards.

I have commented out the event handler in the designer and added my own in the user control but nothing seems to stop the original event code overwriting what I am setting the state to.

Original Code
private void previousPageToolStripMenuItem_Click(object sender, EventArgs e)
        {
            NZRB_Global.Utils.LogToolStripMenuItemClick(sender, "previousPageToolStripMenuItem");

            if (null != ButtonPreviousPageClicked)
            {
                ButtonPreviousPageClicked(this, e);
                m_pbState = PTRB_STATE.PBS_TAKE;
                DisableMenuItemPreviousPage();
                this.Text = "Take " + m_CurrentPage + " of " + m_NumberOfPages;
            }
        }

Open in new window


User Control designer (commented out)
 //  this.ptrBtnResults.ButtonPreviousPageClicked += new NZRB_Button.PreviewTakeRemoveButton.ButtonPreviousPageHandler(this.ptrBtnResults_ButtonPreviousPageClicked);

Open in new window


Initialisation of event in user control
this.ptrBtnResults.ButtonPreviousPageClicked += new PreviewTakeRemoveButton.ButtonPreviousPageHandler(ButtonPreviousPageClicked);

Open in new window



New Event Code on user control
private void ButtonPreviousPageClicked(object sender, EventArgs e)
        {
            if (inRaceSceneControl.mainScenes.Contains(NZRB_Global.Consts.DIRECTOR_FF_RESULTS))
            {
                inRaceSceneControl.ClearScene(true, NZRB_Global.Consts.DIRECTOR_FF_RESULTS, Consts.GFX_LBAR_LAYER);
                inRaceSceneControl.ClearScene(false, NZRB_Global.Consts.DIRECTOR_FF_RESULTS, Consts.GFX_LBAR_LAYER);
                ptrBtnResults.ResetButton();
               
            }
        }

Open in new window

Avatar of Daniel Van Der Werken
Daniel Van Der Werken
Flag of United States of America image

My recommendation: Set the page directive for the aspx page to AutoEventWireup = "false". See what that does for you.
ASKER CERTIFIED SOLUTION
Avatar of jetbet
jetbet
Flag of New Zealand image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer