public void setStatus() { RadLabelElement labelElement = new RadLabelElement(); labelElement.Text = C.vUserName + "@" + C.vProfileName + " Sucursal:" + C.vSucursalName; RadLabelElement labelElement2 = new RadLabelElement(); labelElement2.Font = new Font("Cambria", 16); labelElement2.Text = C.vCompanyName; RadButtonElement buttonElement = new RadButtonElement(); buttonElement.Text = "My ButtonElement"; buttonElement.Visibility = ElementVisibility.Hidden; //buttonElement.Click += new EventHandler(buttonElement_Click); RadRepeatButtonElement repeatButtonElement = new RadRepeatButtonElement(); repeatButtonElement.Text = "My Repeat button"; repeatButtonElement.Visibility = ElementVisibility.Hidden; // repeatButtonElement.Click += new EventHandler(repeatButtonElement_Click); CommandBarSeparator separator = new CommandBarSeparator(); RadProgressBarElement progressBarElement = new RadProgressBarElement(); progressBarElement.Text = "My Progress Bar"; progressBarElement.Visibility = ElementVisibility.Hidden; radStatusStrip1.Items.AddRange(new RadItem[] { labelElement, buttonElement, repeatButtonElement, separator, progressBarElement, labelElement2 }); }
/// <summary> /// Creates the UI elements /// </summary> public void InitializeUI() { // Begin UndoStep Project.UndoContext.BeginUndoStep("Add Buttons"); try { // Create a new tab. RibbonTab ribbonTab = new RibbonTab("MyTab", "MyTab"); // Make tab as active tab UIEnvironment.ActiveRibbonTab = ribbonTab; // Create a group for buttons RibbonGroup ribbonGroup = new RibbonGroup("MyButtons", "MyButton"); // Create first small button CommandBarButton buttonFirst = new CommandBarButton("MyFirstButton", "MyFirstButton"); buttonFirst.HelpText = "Help text for small button"; // buttonFirst.Image = Image.FromFile(@"../....); // Set the image for the button buttonFirst.DefaultEnabled = true; ribbonGroup.Controls.Add(buttonFirst); // Include Seperator between buttons CommandBarSeparator separator = new CommandBarSeparator(); ribbonGroup.Controls.Add(separator); // Create second button. The largeness of the button is determined by RibbonControlLayout CommandBarButton buttonSecond = new CommandBarButton("MySecondButton", "MySecondButton"); buttonSecond.HelpText = "Help text for large button"; // Set the image of the button. //buttonSecond.Image = Image.FromFile... buttonSecond.DefaultEnabled = true; ribbonGroup.Controls.Add(buttonSecond); // Set the size of the buttons RibbonControlLayout[] ribbonControlLayout = { RibbonControlLayout.Small, RibbonControlLayout.Large }; ribbonGroup.SetControlLayout(buttonFirst, ribbonControlLayout[0]); ribbonGroup.SetControlLayout(buttonSecond, ribbonControlLayout[1]); // Add ribbon group to ribbon tab ribbonTab.Groups.Add(ribbonGroup); // Add an event handler buttonFirst.UpdateCommandUI += new UpdateCommandUIEventHandler(EventManager.Instance.button_UpdateCommandUI); // Add an event handler for pressing the button buttonFirst.ExecuteCommand += new ExecuteCommandEventHandler(EventManager.Instance.button_ExecuteCommand); } catch (Exception ex) { Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback); Logger.AddMessage(new LogMessage(ex.Message.ToString())); } finally { Project.UndoContext.EndUndoStep(); } }
//首先创建一个ribbonTab,功能栏的一个选项 //接着创建一个ribbonGroup 是button的group //创建button 设定属性 放入ribbonGroup //对每个button设定相应的处理事件。 private static void CreateButton() { Project.UndoContext.BeginUndoStep("Add Buttons"); try { //在功能栏添加了一个叫Mytab的选项 RibbonTab ribbonTab = new RibbonTab("MyTab", "MyAdd-in"); UIEnvironment.RibbonTabs.Add(ribbonTab); UIEnvironment.ActiveRibbonTab = ribbonTab; RibbonGroup ribbonGroup = new RibbonGroup("Mybutton", "Status"); // Create first small button (id,text) CommandBarButton buttonFirst = new CommandBarButton("MyFirstButton", "OpenStatusWindow"); buttonFirst.HelpText = "Help text for small button"; // buttonFirst.Image = global::RobotStudioEmptyAddin1.Properties.Resources.iconCFimport; buttonFirst.DefaultEnabled = true; ribbonGroup.Controls.Add(buttonFirst); //Include Seperator between buttons CommandBarSeparator seperator = new CommandBarSeparator(); ribbonGroup.Controls.Add(seperator); // Create second button. The largeness of the button is determined by RibbonControlLayout CommandBarButton buttonSecond = new CommandBarButton("MySecondButton", "TestButton"); buttonSecond.HelpText = "Help text for large button"; buttonSecond.DefaultEnabled = true; ribbonGroup.Controls.Add(buttonSecond); // Set the size of the buttons. RibbonControlLayout[] ribbonControlLayout = { RibbonControlLayout.Small, RibbonControlLayout.Large }; ribbonGroup.SetControlLayout(buttonFirst, ribbonControlLayout[0]); ribbonGroup.SetControlLayout(buttonSecond, ribbonControlLayout[1]); //Add ribbon group to ribbon tab ribbonTab.Groups.Add(ribbonGroup); // Add an event handler. buttonFirst.UpdateCommandUI += new UpdateCommandUIEventHandler(button_UpdateCommandUI); // Add an event handler for pressing the button. buttonFirst.ExecuteCommand += new ExecuteCommandEventHandler(button_ExecuteCommand); buttonSecond.UpdateCommandUI += new UpdateCommandUIEventHandler(button2_UpdateCommandUI); buttonSecond.ExecuteCommand += new ExecuteCommandEventHandler(button2_ExecuteCommand); } catch (Exception ex) { Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback); Logger.AddMessage(new LogMessage(ex.Message.ToString())); } finally { Project.UndoContext.EndUndoStep(); } }
protected CommandBarItem CreateMenuItem(ChoiceBase choice) { //note that we could handle the details of display in two different ways. //either we can leave this up to the normal display mechanism, which will do its own polling, //or we could just build the menu in the desired state right here (enable checked etc.) UIItemDisplayProperties display = choice.GetDisplayProperties(); string label = display.Text; bool isSeparatorBar = (label == "-"); label = label.Replace("_", "&"); Image image = null; if (display.ImageLabel != "default") { image = m_smallImages.GetImage(display.ImageLabel); } CommandBarItem menuItem; if (choice is CommandChoice) { if (isSeparatorBar) { menuItem = new CommandBarSeparator(); } else { menuItem = new CommandBarButton(image, label, new EventHandler(OnClick)); } } else { CommandBarCheckBox cb = new CommandBarCheckBox(image, label); cb.Click += new System.EventHandler(choice.OnClick); cb.IsChecked = display.Checked; menuItem = cb; } if (!isSeparatorBar) { ((CommandBarButtonBase)menuItem).Shortcut = choice.Shortcut; } menuItem.Tag = choice; menuItem.IsEnabled = !isSeparatorBar && display.Enabled; menuItem.IsVisible = display.Visible; choice.ReferenceWidget = menuItem; return(menuItem); }
protected CommandBarItem CreateMenuItem(ChoiceBase choice) { //note that we could handle the details of display in two different ways. //either we can leave this up to the normal display mechanism, which will do its own polling, //or we could just build the menu in the desired state right here (enable checked etc.) UIItemDisplayProperties display = choice.GetDisplayProperties(); string label = display.Text; bool isSeparatorBar = (label == "-"); label = label.Replace("_", "&"); Image image = null; if (display.ImageLabel!= "default") image = m_smallImages.GetImage(display.ImageLabel); CommandBarItem menuItem; if(choice is CommandChoice) { if (isSeparatorBar) menuItem = new CommandBarSeparator(); else menuItem = new CommandBarButton(image, label, new EventHandler(OnClick)); } else { CommandBarCheckBox cb = new CommandBarCheckBox(image, label); cb.Click += new System.EventHandler(choice.OnClick); cb.IsChecked = display.Checked; menuItem = cb; } if (!isSeparatorBar) ((CommandBarButtonBase)menuItem).Shortcut = choice.Shortcut; menuItem.Tag = choice; menuItem.IsEnabled = !isSeparatorBar && display.Enabled; menuItem.IsVisible = display.Visible; choice.ReferenceWidget = menuItem; return menuItem; }