• 利用UtilityLibrary.dll WeifenLuo.WinFormsUI.Docking.dll控件创建工具栏效果


    需求:

    1.四个窗体 MainToolWindow(左边工具栏),MainForom(主窗体),form1(常规窗体)

    form2(测试窗体)

    2. 需要两个文件

    UtilityLibrary.dll

    WeifenLuo.WinFormsUI.Docking.dll

    具体步骤如下:

    1.设置MainForm的ISMdiContainer为True;

    在MainForm中引用WeifenLuo.WinFormsUI.Docking.dll,然后在工具栏点选项卡,

    添加控件dockPanel1拖至窗体,

    设置DOCK为Fill

    RightToLeftLayOut为True,

    2.在MianToolWindow引用UtilityLibrary.dll,然后在工具栏点选项卡,

    添加控件outlookBar1至窗体,再拖一个ImageList1,在Images里加入图片

    具体代码如下:

    MainForm.cs

    public partial class MainForm : Form 
        { 
            #region 属性字段 
            private MainToolWindow mainToolWin = new MainToolWindow(); 
            #endregion

     

            public MainForm() 
            { 
                InitializeComponent(); 
                mainToolWin.Show(this.dockPanel1, DockState.DockLeft); 
            }

    private DockContent FindDocument(string text) 
            { 
                if (dockPanel1.DocumentStyle == DocumentStyle.SystemMdi) 
                { 
                    foreach (Form form in MdiChildren) 
                    { 
                        if (form.Text == text) 
                        { 
                            return form as DockContent; 
                        } 
                    }

                    return null; 
                } 
                else 
                { 
                    foreach (DockContent content in dockPanel1.Documents) 
                    { 
                        if (content.DockHandler.TabText == text) 
                        { 
                            return content; 
                        } 
                    }

                    return null; 
                } 
            }

            public DockContent ShowContent(string caption, Type formType) 
            { 
                DockContent frm = FindDocument(caption); 
                if (frm == null) 
                { 
                    frm = Activator.CreateInstance(formType) as DockContent; 
                    frm.DockHandler.TabText = caption; 
                    frm.Show(dockPanel1); 
                } 
                frm.Show(dockPanel1, DockState.Document); 
                frm.BringToFront(); 
                return frm; 
            }

    }

    MainToolWindow.cs

        public partial class MainToolWindow : DockContent 
        { 
            
            public MainToolWindow() 
            { 
                InitializeComponent(); 
            } 

            private void Form2_Load(object sender, EventArgs e) 
            { 
                setBase.Items.Add(new OutlookBarItem("常规",0)); 
                setBase.Items.Add(new OutlookBarItem("测试",0)); 
                outlookBar1.ItemClicked += new OutlookBarItemClickedHandler(OnOutlookBarItemClicked); 
               this.panel1.Controls.AddRange(new Control[] { outlookBar1 }); 
            }

            private void OnOutlookBarItemClicked(OutlookBarBand band, OutlookBarItem item) 
            { 
                switch (item.Text) 
                { 
                    case "常规": 
                        { 
                            Form1.getinstance(DockPanel); 
                            break; 
                        } 
                    case "测试": 
                        { 
                            Form2.getinstance(DockPanel); 
                            break; 
                        } 
                        default: 
                        break; 
                } 
            } 
        }

    Fom1.cs的代码:

    public partial class Form1 : DockContent 
        { 
            public Form1() 
            { 
                InitializeComponent(); 
            }

            private static Form1 _initialize = null;

            public static Form1 getinstance(DockPanel p) 
            { 
                if (_initialize == null || _initialize.IsDisposed) 
                { 
                    _initialize = new Form1(); 
                } 
                _initialize.Show(p); 
                _initialize.Activate();

                return _initialize; 
            } 
        }

    form2同Form1,

    效果图:


  • 相关阅读:
    刘瑜写给女儿的信:愿你慢慢长大
    Linux 程序编译过程的来龙去脉
    2018新版驾照驾照psd模板下载
    最新行驶证 驾照ps模板psd模板
    《我不是药神》票房超25亿 曝片段呈现群像式演技
    微信小程序打开手机浏览器访问置顶网页
    微信如何打开手机浏览器
    微信发一个网址打开后自动调用手机自带默认浏览器或提示选择浏览器打开如何实现?
    网页跳转微信关注页面
    网页跳转微信添加页面
  • 原文地址:https://www.cnblogs.com/fanxingthink/p/4176165.html
Copyright © 2020-2023  润新知