private CommandBar oCommandBarWrite = null; private CommandBarButton oButtonNew = null;
/// <summary> /// Called when the document is opened. /// </summary> protected void ThisDocument_Open() { setupCommandBars(); ... }
private void setupCommandBars() { ThisApplication.CustomizationContext = ThisDocument; setupWriteCommandBar(); }
private void setupWriteCommandBar() { oCommandBarWrite = ThisApplication.CommandBars.Add("Tech Head Brothers - Write", oMissing, oMissing, true); this.AddButton(ref oCommandBarWrite, ref oButtonNew, new _CommandBarButtonEvents_ClickEventHandler(oButtonNew_Click), "New Document", 12); ... oCommandBarWrite.Visible = true; }
private void AddButton(ref CommandBar oCommandBar, ref CommandBarButton oButton, _CommandBarButtonEvents_ClickEventHandler handler, string caption, int faceid) { // Add a button to the command bar. oButton = (CommandBarButton) oCommandBar.Controls.Add(MsoControlType.msoControlButton, oMissing, oMissing, oMissing); // Set the caption and face ID. oButton.Caption = caption; oButton.FaceId = faceid; // Set up a delegate for the Click event. oButton.Click += handler; }
private void oButtonNew_Click(CommandBarButton Ctrl, ref bool Cancel) { ... }