locked
The button click event does not work ?? RRS feed

  • Question

  • HI everyone

    i add a button on excel in a excel-addin project and  register a click event 
    but the click event can only work once 
    please help me thanks 
    code:

    private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {
        AddButtonForCommandBar("dataHelper", Office.MsoButtonStyle.msoButtonIconAndCaption, btn_Click);
    }

    private void AddButtonForCommandBar(string commannText, Office.MsoButtonStyle style, Office._CommandBarButtonEvents_ClickEventHandler handler)
            {
                try
                {
                    Office.CommandBarButton btn;
                    Image image = null;
                    string imageUrl = string.Empty;
                    btn =
                        Application.CommandBars["Helper"].Controls.Add(Office.MsoControlType.msoControlButton, missing,
                                                                       missing, missing, missing) as Office.CommandBarButton;
                    btn.Caption = commannText;
                    btn.Style = style;
                    btn.Click += handler;
            }
     public void btn_Click(Office.CommandBarButton ctrl, ref Boolean cancelDefault)
            {
                
                    this.Application.WindowState = Microsoft.Office.Interop.Excel.XlWindowState.xlNormal;
                    Application.Left = 230;
                    Application.Width = 733;
                    Application.Top = 0;
                    DataHelper_1 helperForm = new DataHelper_1();
                    helperForm.Location = new Point(0, 0);
                    helperForm.Show();

            }
    Thursday, May 7, 2009 9:18 AM

Answers

  • Declare the button at class level and try

    HTH
    Jaz
    • Proposed as answer by jaz.jazEditor Thursday, May 7, 2009 4:02 PM
    • Marked as answer by starinight Friday, May 8, 2009 1:11 AM
    Thursday, May 7, 2009 4:01 PM
    Answerer

All replies