Dev BarManager使用方法

作者:jiankunking 出处:http://blog.csdn.net/jiankunking

近期使用BarManager时候。发现一个问题就是在一開始把BarManager控件拖到窗口上的时候,控件上会有Addbutton,例如以下图:

此时,新增button或者其余类型的控件,方便无比。但有时候,当你新增完各个BarItem(Bar上的各个小控件,比方:BarButtonItem、BarCheckItem等等)后。再过一段时间。突然又有需求,要新增BarItem,发现Addbutton木有了。那应该怎么办呢?

解决方式:

通过代码加入。

代码改动前:

namespace IconTest
{
    partial class Form1
    {
        /// <summary>
        /// 必需的设计器变量。
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// 清理全部正在使用的资源。
        /// </summary>
        /// <param name="disposing">假设应释放托管资源。为 true。否则为 false。</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows 窗口设计器生成的代码

        /// <summary>
        /// 设计器支持所需的方法 - 不要
        /// 使用代码编辑器改动此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.barManager1 = new DevExpress.XtraBars.BarManager(this.components);
            this.bar1 = new DevExpress.XtraBars.Bar();
            this.bar2 = new DevExpress.XtraBars.Bar();
            this.barButtonItemDemo = new DevExpress.XtraBars.BarButtonItem();
            this.bar3 = new DevExpress.XtraBars.Bar();
            this.barDockControlTop = new DevExpress.XtraBars.BarDockControl();
            this.barDockControlBottom = new DevExpress.XtraBars.BarDockControl();
            this.barDockControlLeft = new DevExpress.XtraBars.BarDockControl();
            this.barDockControlRight = new DevExpress.XtraBars.BarDockControl();
            ((System.ComponentModel.ISupportInitialize)(this.barManager1)).BeginInit();
            this.SuspendLayout();
            //
            // barManager1
            //
            this.barManager1.Bars.AddRange(new DevExpress.XtraBars.Bar[] {
            this.bar1,
            this.bar2,
            this.bar3});
            this.barManager1.DockControls.Add(this.barDockControlTop);
            this.barManager1.DockControls.Add(this.barDockControlBottom);
            this.barManager1.DockControls.Add(this.barDockControlLeft);
            this.barManager1.DockControls.Add(this.barDockControlRight);
            this.barManager1.Form = this;
            this.barManager1.Items.AddRange(new DevExpress.XtraBars.BarItem[] {
            this.barButtonItemDemo});
            this.barManager1.MainMenu = this.bar2;
            this.barManager1.MaxItemId = 2;
            this.barManager1.StatusBar = this.bar3;
            //
            // bar1
            //
            this.bar1.BarName = "Tools";
            this.bar1.DockCol = 0;
            this.bar1.DockRow = 1;
            this.bar1.DockStyle = DevExpress.XtraBars.BarDockStyle.Top;
            this.bar1.Text = "Tools";
            //
            // bar2
            //
            this.bar2.BarName = "Main menu";
            this.bar2.DockCol = 0;
            this.bar2.DockRow = 0;
            this.bar2.DockStyle = DevExpress.XtraBars.BarDockStyle.Top;
            this.bar2.LinksPersistInfo.AddRange(new DevExpress.XtraBars.LinkPersistInfo[] {
            new DevExpress.XtraBars.LinkPersistInfo(this.barButtonItemDemo)});
            this.bar2.OptionsBar.MultiLine = true;
            this.bar2.OptionsBar.UseWholeRow = true;
            this.bar2.Text = "Main menu";
            //
            // barButtonItemDemo
            //
            this.barButtonItemDemo.Caption = "barButtonItemDemo";
            this.barButtonItemDemo.Id = 0;
            this.barButtonItemDemo.Name = "barButtonItemDemo";
            //
            // bar3
            //
            this.bar3.BarName = "Status bar";
            this.bar3.CanDockStyle = DevExpress.XtraBars.BarCanDockStyle.Bottom;
            this.bar3.DockCol = 0;
            this.bar3.DockRow = 0;
            this.bar3.DockStyle = DevExpress.XtraBars.BarDockStyle.Bottom;
            this.bar3.OptionsBar.AllowQuickCustomization = false;
            this.bar3.OptionsBar.DrawDragBorder = false;
            this.bar3.OptionsBar.UseWholeRow = true;
            this.bar3.Text = "Status bar";
            //
            // barDockControlTop
            //
            this.barDockControlTop.CausesValidation = false;
            this.barDockControlTop.Dock = System.Windows.Forms.DockStyle.Top;
            this.barDockControlTop.Location = new System.Drawing.Point(0, 0);
            this.barDockControlTop.Size = new System.Drawing.Size(414, 49);
            //
            // barDockControlBottom
            //
            this.barDockControlBottom.CausesValidation = false;
            this.barDockControlBottom.Dock = System.Windows.Forms.DockStyle.Bottom;
            this.barDockControlBottom.Location = new System.Drawing.Point(0, 320);
            this.barDockControlBottom.Size = new System.Drawing.Size(414, 23);
            //
            // barDockControlLeft
            //
            this.barDockControlLeft.CausesValidation = false;
            this.barDockControlLeft.Dock = System.Windows.Forms.DockStyle.Left;
            this.barDockControlLeft.Location = new System.Drawing.Point(0, 49);
            this.barDockControlLeft.Size = new System.Drawing.Size(0, 271);
            //
            // barDockControlRight
            //
            this.barDockControlRight.CausesValidation = false;
            this.barDockControlRight.Dock = System.Windows.Forms.DockStyle.Right;
            this.barDockControlRight.Location = new System.Drawing.Point(414, 49);
            this.barDockControlRight.Size = new System.Drawing.Size(0, 271);
            //
            // Form1
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(414, 343);
            this.Controls.Add(this.barDockControlLeft);
            this.Controls.Add(this.barDockControlRight);
            this.Controls.Add(this.barDockControlBottom);
            this.Controls.Add(this.barDockControlTop);
            this.Name = "Form1";
            this.Text = "Form1";
            ((System.ComponentModel.ISupportInitialize)(this.barManager1)).EndInit();
            this.ResumeLayout(false);

        }

        #endregion

        private DevExpress.XtraBars.BarManager barManager1;
        private DevExpress.XtraBars.Bar bar1;
        private DevExpress.XtraBars.Bar bar2;
        private DevExpress.XtraBars.Bar bar3;
        private DevExpress.XtraBars.BarDockControl barDockControlTop;
        private DevExpress.XtraBars.BarDockControl barDockControlBottom;
        private DevExpress.XtraBars.BarDockControl barDockControlLeft;
        private DevExpress.XtraBars.BarDockControl barDockControlRight;
        private DevExpress.XtraBars.BarButtonItem barButtonItemDemo;

    }
}

此时,界面上仅仅有barButtonItemDemo一个控件。如图:

小注:尽管此时Bar上有Addbutton,但我们仍然通过代码加入BarItem。

比方我们仍然要加入一个buttonBarButtonItem,代码例如以下:

namespace IconTest
{
    partial class Form1
    {
        /// <summary>
        /// 必需的设计器变量。
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// 清理全部正在使用的资源。

/// </summary>
        /// <param name="disposing">假设应释放托管资源。为 true。否则为 false。</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows 窗口设计器生成的代码

        /// <summary>
        /// 设计器支持所需的方法 - 不要
        /// 使用代码编辑器改动此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.barManager1 = new DevExpress.XtraBars.BarManager(this.components);
            this.bar1 = new DevExpress.XtraBars.Bar();
            this.bar2 = new DevExpress.XtraBars.Bar();
            this.barButtonItemDemo = new DevExpress.XtraBars.BarButtonItem();
            //手动加入以下代码 CodeTest
            this.CodeTest = new DevExpress.XtraBars.BarButtonItem();
            this.bar3 = new DevExpress.XtraBars.Bar();
            this.barDockControlTop = new DevExpress.XtraBars.BarDockControl();
            this.barDockControlBottom = new DevExpress.XtraBars.BarDockControl();
            this.barDockControlLeft = new DevExpress.XtraBars.BarDockControl();
            this.barDockControlRight = new DevExpress.XtraBars.BarDockControl();
            ((System.ComponentModel.ISupportInitialize)(this.barManager1)).BeginInit();
            this.SuspendLayout();
            //
            // barManager1
            //
            this.barManager1.Bars.AddRange(new DevExpress.XtraBars.Bar[] {
            this.bar1,
            this.bar2,
            this.bar3});
            this.barManager1.DockControls.Add(this.barDockControlTop);
            this.barManager1.DockControls.Add(this.barDockControlBottom);
            this.barManager1.DockControls.Add(this.barDockControlLeft);
            this.barManager1.DockControls.Add(this.barDockControlRight);
            this.barManager1.Form = this;
            this.barManager1.Items.AddRange(new DevExpress.XtraBars.BarItem[] {
            this.barButtonItemDemo
            //手动加入以下代码 CodeTest
            ,
            this.CodeTest});
            this.barManager1.MainMenu = this.bar2;
            this.barManager1.MaxItemId = 3;
            this.barManager1.StatusBar = this.bar3;
            //
            // bar1
            //
            this.bar1.BarName = "Tools";
            this.bar1.DockCol = 0;
            this.bar1.DockRow = 0;
            this.bar1.DockStyle = DevExpress.XtraBars.BarDockStyle.Top;
            this.bar1.Text = "Tools";
            //
            // bar2
            //
            this.bar2.BarName = "Main menu";
            this.bar2.DockCol = 0;
            this.bar2.DockRow = 1;
            this.bar2.DockStyle = DevExpress.XtraBars.BarDockStyle.Top;
            this.bar2.LinksPersistInfo.AddRange(new DevExpress.XtraBars.LinkPersistInfo[] {
            new DevExpress.XtraBars.LinkPersistInfo(this.barButtonItemDemo)
           // 手动加入以下代码 CodeTest
            ,
            new DevExpress.XtraBars.LinkPersistInfo(this.CodeTest)});
            this.bar2.OptionsBar.MultiLine = true;
            this.bar2.OptionsBar.UseWholeRow = true;
            this.bar2.Text = "Main menu";
            //
            // barButtonItemDemo
            //
            this.barButtonItemDemo.Caption = "barButtonItemDemo";
            this.barButtonItemDemo.Id = 0;
            this.barButtonItemDemo.Name = "barButtonItemDemo";
            //
            // CodeTest
            // 手动加入以下代码 CodeTest
            this.CodeTest.Caption = "CodeTest";
            this.CodeTest.Id = 2;
            this.CodeTest.Name = "CodeTest";
            //
            // bar3
            //
            this.bar3.BarName = "Status bar";
            this.bar3.CanDockStyle = DevExpress.XtraBars.BarCanDockStyle.Bottom;
            this.bar3.DockCol = 0;
            this.bar3.DockRow = 0;
            this.bar3.DockStyle = DevExpress.XtraBars.BarDockStyle.Bottom;
            this.bar3.OptionsBar.AllowQuickCustomization = false;
            this.bar3.OptionsBar.DrawDragBorder = false;
            this.bar3.OptionsBar.UseWholeRow = true;
            this.bar3.Text = "Status bar";
            //
            // barDockControlTop
            //
            this.barDockControlTop.CausesValidation = false;
            this.barDockControlTop.Dock = System.Windows.Forms.DockStyle.Top;
            this.barDockControlTop.Location = new System.Drawing.Point(0, 0);
            this.barDockControlTop.Size = new System.Drawing.Size(414, 49);
            //
            // barDockControlBottom
            //
            this.barDockControlBottom.CausesValidation = false;
            this.barDockControlBottom.Dock = System.Windows.Forms.DockStyle.Bottom;
            this.barDockControlBottom.Location = new System.Drawing.Point(0, 320);
            this.barDockControlBottom.Size = new System.Drawing.Size(414, 23);
            //
            // barDockControlLeft
            //
            this.barDockControlLeft.CausesValidation = false;
            this.barDockControlLeft.Dock = System.Windows.Forms.DockStyle.Left;
            this.barDockControlLeft.Location = new System.Drawing.Point(0, 49);
            this.barDockControlLeft.Size = new System.Drawing.Size(0, 271);
            //
            // barDockControlRight
            //
            this.barDockControlRight.CausesValidation = false;
            this.barDockControlRight.Dock = System.Windows.Forms.DockStyle.Right;
            this.barDockControlRight.Location = new System.Drawing.Point(414, 49);
            this.barDockControlRight.Size = new System.Drawing.Size(0, 271);
            //
            // Form1
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(414, 343);
            this.Controls.Add(this.barDockControlLeft);
            this.Controls.Add(this.barDockControlRight);
            this.Controls.Add(this.barDockControlBottom);
            this.Controls.Add(this.barDockControlTop);
            this.Name = "Form1";
            this.Text = "Form1";
            ((System.ComponentModel.ISupportInitialize)(this.barManager1)).EndInit();
            this.ResumeLayout(false);

        }

        #endregion

        private DevExpress.XtraBars.BarManager barManager1;
        private DevExpress.XtraBars.Bar bar1;
        private DevExpress.XtraBars.Bar bar2;
        private DevExpress.XtraBars.Bar bar3;
        private DevExpress.XtraBars.BarDockControl barDockControlTop;
        private DevExpress.XtraBars.BarDockControl barDockControlBottom;
        private DevExpress.XtraBars.BarDockControl barDockControlLeft;
        private DevExpress.XtraBars.BarDockControl barDockControlRight;
        private DevExpress.XtraBars.BarButtonItem barButtonItemDemo;
        //手动加入以下代码 CodeTest
        private DevExpress.XtraBars.BarButtonItem CodeTest;

    }
}

此处新增控件为CodeTest,效果例如以下图:

此时。就能够进行改动图片,点击事件之类的处理了,与通过Addbutton生成的使用方法一致。

小结:所谓的通过代码加入BarItem。即是參照之前的代码,手动复制改动一下就可以。

时间: 2024-10-12 21:08:43

Dev BarManager使用方法的相关文章

DEV LookUpEdit 使用方法

public class field { public string Name { get; set; } public string Explain { get; set; } } List<field> list = new List<field>(); private void simpleButton1_Click(object sender, EventArgs e) { lueList.Properties.DataSource = list; //设置数据源 lueL

Dev BarManager用法

最近使用BarManager时候,发现一个问题就是在一开始把BarManager控件拖到窗体上的时候,控件上会有Add按钮,如下图: 此时,新增按钮或者其余类型的控件,方便无比.但有时候,当你新增完各个BarItem(Bar上的各个小控件,比如:BarButtonItem.BarCheckItem等等)后,再过一段时间,突然又有需求,要新增BarItem,发现Add按钮木有了,那应该怎么办呢? 解决方案: 通过代码添加. 代码修改前: namespace IconTest { partial c

dev EditMask 设置方法

官方帮助地址: https://documentation.devexpress.com/WindowsForms/583/Controls-and-Libraries/Editors-and-Simple-Controls/Simple-Editors/Concepts/Masks/Mask-Editors-Overview 代码实例: RepositoryItemTextEdit repositoryItemTextEdit1 = new RepositoryItemTextEdit();

Linux清空文件内容方法

Linux快速清空文件内容的方法 方法1 [[email protected] ~]# > filename 方法2 [[email protected] ~]# cat /dev/null > filename 方法3 [[email protected] ~]# echo /dev/null > filename 方法4 [[email protected] ~]# : > filename 注释:":"是一个占位符,不产生任何输出 方法5 [[email 

手动刷入recovery的方法

手动刷入recovery的方法: a:fastboot下刷recovery的方法: fastboot  flash  recovery [recovery文件的路径] b:手机在系统模式或者recovery模式下刷入recovery: 首先将本地的recovery文件push到手机的data/local/tmp目录下(或者其他有su权限的目录下),再dd刷入recovery: dd if=[手机recovery文件的路径] of=[手机recovery分区地址] 例如一加手机:dd if=/tm

监控 MySQL的多种方法

判断mysql是否正常的几种方法 ################################# 方法1:看端口 netstat -lntup|grep 3306|wc -l lsof -i :3306 |wc -l 远程: /telnet/nc/nmap ################################# 方法2:看进程 ps -ef |grep mysqld|wc -l ################################# 方法3:进入mysql 看版本 [

Monkey源码分析番外篇之Android注入事件的三种方法比较

原文:http://www.pocketmagic.net/2012/04/injecting-events-programatically-on-android/#.VEoIoIuUcaV 往下分析monkey事件注入源码之前先了解下在android系统下事件注入的方式,翻译一篇国外文章如下. Method 1: Using internal APIs 方法1:使用内部APIs This approach has its risks, like it is always with intern

linux内核编译与开发

一.Linux内核简介linux kernel map: linux 系统体系结构: linux kernel体系结构: arm有7种工作模式,x86也实现了4个不同级别RING0-RING3,RING0级别最高, 这样linux用户代码运行在RING3下,内核运行在RING0,这样系统本身就得到了 充分的保护 用户空间(用户模式)转到内核空间(系统模式)方法: ·系统调用 ·硬件中断 linux kernel 体系结构: 虚拟文件系统VFS: VFS(虚拟文件系统)隐藏各种文件系统的具体细节,

RAID 的常用模式 及mdadm 命令的应用

一,RAID:独立磁盘冗余阵列(RAID,redundant array of independent disks)是把相同的数据存储在多个硬盘的不同的地方(因此,冗余地)的方法.通过把数据放在多个硬盘上,输入输出操作能以平衡的方式交叠,改良性能.因为多个硬盘增加了平均故障间隔时间(MTBF),储存冗余数据也增加了容错.整个 RAID 由于选择的等级(level 仅用于标识磁盘的组合方式的不同) 不同,而使得整合后的磁盘具有不同的功能, 基本常见的 level 有这几种 "RAID0(条带),