Loading...
Loading...
Compare original and translation side by side
Syncfusion.Windows.Forms.Tools.XPMenus.XPToolBarSyncfusion.Windows.Forms.Tools.XPMenusSyncfusion.Tools.Windows.dllSyncfusion.Windows.Forms.Tools.XPMenus.XPToolBarSyncfusion.Windows.Forms.Tools.XPMenusSyncfusion.Tools.Windows.dllusing Syncfusion.Windows.Forms.Tools.XPMenus;
using System.Windows.Forms;
// Create panel to host toolbar
Panel panel1 = new Panel();
panel1.Dock = DockStyle.Top;
panel1.Height = 50;
// Create XPToolBar
XPToolBar xpToolBar1 = new XPToolBar();
// Create menu items
BarItem fileItem = new BarItem();
fileItem.Text = "File";
ParentBarItem editItem = new ParentBarItem();
editItem.Text = "Edit";
// Add submenu items to Edit
BarItem cutItem = new BarItem { Text = "Cut" };
BarItem copyItem = new BarItem { Text = "Copy" };
BarItem pasteItem = new BarItem { Text = "Paste" };
editItem.Items.AddRange(new BarItem[] { cutItem, copyItem, pasteItem });
DropDownBarItem viewItem = new DropDownBarItem();
viewItem.Text = "View";
// Add items to toolbar
xpToolBar1.Bar.Items.AddRange(new BarItem[] {
fileItem,
editItem,
viewItem
});
// Add toolbar to panel
panel1.Controls.Add(xpToolBar1);
// Add panel to form
this.Controls.Add(panel1);using Syncfusion.Windows.Forms.Tools.XPMenus;
using System.Windows.Forms;
// Create panel to host toolbar
Panel panel1 = new Panel();
panel1.Dock = DockStyle.Top;
panel1.Height = 50;
// Create XPToolBar
XPToolBar xpToolBar1 = new XPToolBar();
// Create menu items
BarItem fileItem = new BarItem();
fileItem.Text = "File";
ParentBarItem editItem = new ParentBarItem();
editItem.Text = "Edit";
// Add submenu items to Edit
BarItem cutItem = new BarItem { Text = "Cut" };
BarItem copyItem = new BarItem { Text = "Copy" };
BarItem pasteItem = new BarItem { Text = "Paste" };
editItem.Items.AddRange(new BarItem[] { cutItem, copyItem, pasteItem });
DropDownBarItem viewItem = new DropDownBarItem();
viewItem.Text = "View";
// Add items to toolbar
xpToolBar1.Bar.Items.AddRange(new BarItem[] {
fileItem,
editItem,
viewItem
});
// Add toolbar to panel
panel1.Controls.Add(xpToolBar1);
// Add panel to form
this.Controls.Add(panel1);// Apply Office2016 Colorful theme
xpToolBar1.Style = VisualStyle.Office2016Colorful;// Apply Office2016 Colorful theme
xpToolBar1.Style = VisualStyle.Office2016Colorful;// Create File menu with submenu
ParentBarItem fileMenu = new ParentBarItem();
fileMenu.Text = "File";
// Add submenu items
BarItem newItem = new BarItem { Text = "New", Image = Properties.Resources.New };
BarItem openItem = new BarItem { Text = "Open", Image = Properties.Resources.Open };
BarItem saveItem = new BarItem { Text = "Save", Image = Properties.Resources.Save };
BarItem separator = new BarItem { BarItemType = BarItemType.Separator };
BarItem exitItem = new BarItem { Text = "Exit" };
fileMenu.Items.AddRange(new BarItem[] {
newItem,
openItem,
saveItem,
separator,
exitItem
});
// Handle click events
newItem.Click += (s, e) => CreateNewDocument();
openItem.Click += (s, e) => OpenDocument();
saveItem.Click += (s, e) => SaveDocument();
exitItem.Click += (s, e) => Application.Exit();
xpToolBar1.Bar.Items.Add(fileMenu);// Create File menu with submenu
ParentBarItem fileMenu = new ParentBarItem();
fileMenu.Text = "File";
// Add submenu items
BarItem newItem = new BarItem { Text = "New", Image = Properties.Resources.New };
BarItem openItem = new BarItem { Text = "Open", Image = Properties.Resources.Open };
BarItem saveItem = new BarItem { Text = "Save", Image = Properties.Resources.Save };
BarItem separator = new BarItem { BarItemType = BarItemType.Separator };
BarItem exitItem = new BarItem { Text = "Exit" };
fileMenu.Items.AddRange(new BarItem[] {
newItem,
openItem,
saveItem,
separator,
exitItem
});
// Handle click events
newItem.Click += (s, e) => CreateNewDocument();
openItem.Click += (s, e) => OpenDocument();
saveItem.Click += (s, e) => SaveDocument();
exitItem.Click += (s, e) => Application.Exit();
xpToolBar1.Bar.Items.Add(fileMenu);// Font selector combo box
ComboBoxBarItem fontCombo = new ComboBoxBarItem();
fontCombo.Text = "Font:";
fontCombo.Items.AddRange(new string[] { "Arial", "Calibri", "Times New Roman" });
fontCombo.SelectedIndex = 0;
// Font size text box
TextBoxBarItem fontSizeTextBox = new TextBoxBarItem();
fontSizeTextBox.Text = "Size:";
fontSizeTextBox.TextBoxValue = "12";
fontSizeTextBox.MinimumSize = new Size(50, 20);
// Add to toolbar
xpToolBar1.Bar.Items.AddRange(new BarItem[] {
fontCombo,
fontSizeTextBox
});
// Handle changes
fontCombo.SelectedIndexChanged += (s, e) => {
string selectedFont = fontCombo.ChoiceList[fontCombo.SelectedIndex];
ApplyFont(selectedFont);
};// Font selector combo box
ComboBoxBarItem fontCombo = new ComboBoxBarItem();
fontCombo.Text = "Font:";
fontCombo.Items.AddRange(new string[] { "Arial", "Calibri", "Times New Roman" });
fontCombo.SelectedIndex = 0;
// Font size text box
TextBoxBarItem fontSizeTextBox = new TextBoxBarItem();
fontSizeTextBox.Text = "Size:";
fontSizeTextBox.TextBoxValue = "12";
fontSizeTextBox.MinimumSize = new Size(50, 20);
// Add to toolbar
xpToolBar1.Bar.Items.AddRange(new BarItem[] {
fontCombo,
fontSizeTextBox
});
// Handle changes
fontCombo.SelectedIndexChanged += (s, e) => {
string selectedFont = fontCombo.ChoiceList[fontCombo.SelectedIndex];
ApplyFont(selectedFont);
};// Create toolbar with top docking
XPToolBar toolbar = new XPToolBar();
toolbar.Dock = DockStyle.Top;
// Add items
toolbar.Bar.Items.AddRange(new BarItem[] {
new BarItem { Text = "Home" },
new BarItem { Text = "Insert" },
new BarItem { Text = "View" }
});
// Add directly to form (no panel needed for simple top dock)
this.Controls.Add(toolbar);// Create toolbar with top docking
XPToolBar toolbar = new XPToolBar();
toolbar.Dock = DockStyle.Top;
// Add items
toolbar.Bar.Items.AddRange(new BarItem[] {
new BarItem { Text = "Home" },
new BarItem { Text = "Insert" },
new BarItem { Text = "View" }
});
// Add directly to form (no panel needed for simple top dock)
this.Controls.Add(toolbar);// First toolbar level (Menu bar)
Panel menuPanel = new Panel { Dock = DockStyle.Top, Height = 30 };
XPToolBar menuToolbar = new XPToolBar();
menuToolbar.Bar.Items.AddRange(new BarItem[] {
new ParentBarItem { Text = "File" },
new ParentBarItem { Text = "Edit" },
new ParentBarItem { Text = "View" }
});
menuPanel.Controls.Add(menuToolbar);
// Second toolbar level (Quick access)
Panel quickPanel = new Panel { Dock = DockStyle.Top, Height = 40 };
XPToolBar quickToolbar = new XPToolBar();
quickToolbar.Bar.Items.AddRange(new BarItem[] {
new BarItem { Text = "New", Image = Properties.Resources.New },
new BarItem { Text = "Save", Image = Properties.Resources.Save },
new BarItem { Text = "Undo", Image = Properties.Resources.Undo }
});
quickPanel.Controls.Add(quickToolbar);
// Add to form (order matters - add quick toolbar first for correct stacking)
this.Controls.Add(quickPanel);
this.Controls.Add(menuPanel);// First toolbar level (Menu bar)
Panel menuPanel = new Panel { Dock = DockStyle.Top, Height = 30 };
XPToolBar menuToolbar = new XPToolBar();
menuToolbar.Bar.Items.AddRange(new BarItem[] {
new ParentBarItem { Text = "File" },
new ParentBarItem { Text = "Edit" },
new ParentBarItem { Text = "View" }
});
menuPanel.Controls.Add(menuToolbar);
// Second toolbar level (Quick access)
Panel quickPanel = new Panel { Dock = DockStyle.Top, Height = 40 };
XPToolBar quickToolbar = new XPToolBar();
quickToolbar.Bar.Items.AddRange(new BarItem[] {
new BarItem { Text = "New", Image = Properties.Resources.New },
new BarItem { Text = "Save", Image = Properties.Resources.Save },
new BarItem { Text = "Undo", Image = Properties.Resources.Undo }
});
quickPanel.Controls.Add(quickToolbar);
// Add to form (order matters - add quick toolbar first for correct stacking)
this.Controls.Add(quickPanel);
this.Controls.Add(menuPanel);| Property | Type | Description | When to Use |
|---|---|---|---|
| Bar.Items | | Collection of toolbar items | Add/manage toolbar buttons and controls |
| Dock | | Docking position | Position toolbar (Top/Bottom/Left/Right) |
| Style | | Visual theme style | Apply Office2007/2016/Metro themes |
| 属性 | 类型 | 描述 | 适用场景 |
|---|---|---|---|
| Bar.Items | | 工具栏条目集合 | 添加/管理工具栏按钮和控件 |
| Dock | | 停靠位置 | 定位工具栏(顶部/底部/左侧/右侧) |
| Style | | 视觉主题样式 | 应用Office2007/2016/Metro主题 |
| Property | Type | Description | When to Use |
|---|---|---|---|
| Text | | Item text/caption | Set button or menu label |
| Image | | Item icon | Add visual icon to item |
| ToolTip | | Tooltip text | Provide hover information |
| Enabled | | Enable/disable item | Control item interactivity |
| Visible | | Show/hide item | Toggle item visibility |
| 属性 | 类型 | 描述 | 适用场景 |
|---|---|---|---|
| Text | | 条目文本/标题 | 设置按钮或菜单标签 |
| Image | | 条目图标 | 为条目添加视觉图标 |
| ToolTip | | 提示文本 | 提供悬浮提示信息 |
| Enabled | | 启用/禁用条目 | 控制条目交互性 |
| Visible | | 显示/隐藏条目 | 切换条目可见性 |
.Items.ChoiceList.Items.SelectedIndex.TextBoxValueBarItemType = BarItemType.Separator.Items.ChoiceList.Items.SelectedIndex.TextBoxValueBarItemType = BarItemType.SeparatorbarItem1.Click += (sender, e) => {
// Handle button click
MessageBox.Show("Item clicked!");
};
comboBoxBarItem1.SelectedIndexChanged += (sender, e) => {
string selected = comboBoxBarItem1.ChoiceList[comboBoxBarItem1.SelectedIndex];
// Handle selection change
};barItem1.Click += (sender, e) => {
// Handle button click
MessageBox.Show("Item clicked!");
};
comboBoxBarItem1.SelectedIndexChanged += (sender, e) => {
string selected = comboBoxBarItem1.ChoiceList[comboBoxBarItem1.SelectedIndex];
// Handle selection change
};