轻松创建Visual Studio样式的应用程序界面,终极招数放送
本系列教程致力于教大家如何创建流行的应用程序UI,这种经典布局包含代表主要工作区域的选项卡式或 MDI 文档、表单侧面的面板和顶部的主菜单,类似于 Microsoft Visual Studio中的 UI 。
获取工具下载 - DevExpress WinForm v21.1
DevExpress技术交流群4:715863792 欢迎一起进群讨论
在这一部分中,您将向应用程序添加一个Bar Manager组件,并了解如何通过BarItems 与 DocumentManager 和 DockManager 项进行交互。 您可能想用Ribbon Control替换Bar Manager,以下所有说明也适用于 Ribbon Control。但是在此步骤中使用了 Bar Manager 控件,因为它更适合 Visual Studio 应用程序UI。
Step 3 - Bar Manager
1. 在您的工具箱中找到Bar Manager组件并将其拖放到表单上。

2. 添加Bar Manager控件后,将自动创建三个栏,这些栏代表主菜单、状态栏和常规工具栏。 从技术上讲,这些栏是可以显示 BarItemLinks 的相同 Bar 对象,但主菜单栏和状态栏分别分配给 BarManager.MainMenu和 BarManager.StatusBar属性。 下图说明了这些栏(为了可视化目的,每个栏中都添加了一个 BarStaticItem)。

要添加新的栏,请使用Bar Manager智能标记中的相应链接。

要删除现有栏,请在设计时选择它并按 ‘Delete’,或者单击Bar Manager Designer中的相应按钮。对于这个示例,我们只需要主菜单和状态栏,所以可以删除常规栏。

3. 栏要显示BarItemLink 对象 - 到BarItems 的链接。 要将 BarItem 添加到所需的 Bar,请单击 ‘Add’ 按钮并选择所需的 BarItem 类型,将BarSubItem 添加到您的主菜单栏。

您可以右键单击一个项目来自定义它。 例如,选择一种样式,指定是仅显示项目标题、项目字形还是同时显示标题和字形。 要在代码中指定此样式,请使用 BarItemLink.PaintStyle属性。

默认情况下,常规工具栏中的项目仅显示图标,而主菜单中的项目仅显示标题。
4. 您在上一步中添加的 BarStaticItem 是一个可以包含其他项目的子菜单,要将 BarItem 添加到 BarStaticItem,请选择 BarStaticItem 并单击 Add 按钮(使用与向 Bar 添加项时使用相同方法)。将 New BarButtonItem 添加到 File 子菜单,此按钮将向您的应用程序添加一个新文档。
5. 将 BarDockingMenuItem 添加到您的主菜单,这个独特的项目允许您管理应用程序中包含的 DockPanel 和文档。

下面的动画显示了完成上述步骤的大致结果。

DevExpress WinForm拥有180+组件和UI库,能为Windows Forms平台创建具有影响力的业务解决方案。DevExpress WinForms能完美构建流畅、美观且易于使用的应用程序,无论是Office风格的界面,还是分析处理大批量的业务数据,它都能轻松胜任!
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步