CommandBarComboBox Change Event In New Document

Domanda CommandBarComboBox Change Event In New Document

  • giovedì 26 aprile 2012 15:41
     
      Contiene codice

    Hi

    The change event is occured once the visio program launched the first time. After this, the user open another visio document,  the change event is not occured. But I test in word and it is OK

    Code Snippet:
    Office.CommandBar myCommandBar = null;
    Office.CommandBarComboBox ComboBox = null;
    private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {
        this.Application.WindowActivated += new Visio.EApplication_WindowActivatedEventHandler(Application_WindowActivated);
        myCommandBar = this.Application.CommandBars.Add("Test", Office.MsoBarPosition.msoBarTop, false, true);
        myCommandBar.Visible = true;
        ComboBox = this.myCommandBar.Controls.Add(Office.MsoControlType.msoControlComboBox, missing, missing, missing, true) as Office.CommandBarComboBox;
        ComboBox.AddItem("ComboBoxItem1", 1);
        ComboBox.AddItem("ComboBoxItem2", 2);
        ComboBox.Caption = "My ComboBox";
        ComboBox.Tag = "myComboBox";
        ComboBox.Change += new Microsoft.Office.Core._CommandBarComboBoxEvents_ChangeEventHandler(ComboBox_Change);
    }
    void Application_WindowActivated(Visio.Window Window)
    {
        System.Runtime.InteropServices.Marshal.ReleaseComObject(ComboBox);
        ComboBox = null;
        Office.CommandBar bar = this.Application.CommandBars["Test"];
        ComboBox = bar.FindControl(Type.Missing, Type.Missing, "myComboBox", Type.Missing, Type.Missing) as Office.CommandBarComboBox;
        ComboBox.Change += new Microsoft.Office.Core._CommandBarComboBoxEvents_ChangeEventHandler(ComboBox_Change);
    }
    void ComboBox_Change(Microsoft.Office.Core.CommandBarComboBox Ctrl)
    {
        System.Windows.Forms.MessageBox.Show("Changed");
    }


Tutte le risposte

  • venerdì 27 aprile 2012 15:53
    Moderatore
     
     

    Hi CommandBarComboBox In VISIO,

    Welcome to MSDN Forum.

    I'm interested in this issue, and I'll do some research over this issue on the next work day.

    Have a nice weekend.

    Best Regards,
    Quist


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us

  • lunedì 30 aprile 2012 03:01
    Moderatore
     
     

    Hi CommandBarComboBox In VISIO,

    How is everything going?

    I’ve copied the code you provided above, and pasted into my VISIO Add-In project. The change event hasn’t occurred at the first time the Visio launched. It will be nice if you can provide the code of Word edition.

    I’m looking forward to your reply.

    Best Regards,
    Quist


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us