Devperience 12.1 ribbonForm窗体里显示其他窗体

1.首先创建一个windform项目

2.添加一个Ribbon Form,如图所示Dxperience v12.1 Ribbon Form

 

再多建一个Ribbon Form,项目结构如下:

从工具栏拖一个dockManage放到RibbonForm1

如上图所示,选择dockManage的箭头--弹出列表--选择Add Panel at left,然后在dockPanel里加一个navBarGroup,右键navBarGroup添加两个子项。

RibbonForm1要修改属性

IsMdiContainer=True,这样才能在这个窗体里显示其他窗体。

RibbonForm1代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;

namespace WindowsFormsApplication1
{
    public partial class RibbonForm1 : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        public RibbonForm1()
        {
            InitializeComponent();
            initevent();//初始化事件
            MainRibbonForm = this;
        }
        private void initevent()
        {
            navBarItem1.LinkClicked+=new DevExpress.XtraNavBar.NavBarLinkEventHandler(navBarItem1_LinkClicked);
            navBarItem2.LinkClicked+=new DevExpress.XtraNavBar.NavBarLinkEventHandler(navBarItem2_LinkClicked);
        }
        private void navBarItem1_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            nbiOpenLink(new RibbonForm2(), "新开的窗口");
            
        }
        private void navBarItem2_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            nbiOpenLink(new RibbonForm1(), "新开的窗口");

        }
        public static RibbonForm1 MainRibbonForm { get; set; }
        public static void nbiOpenLink(Form frm, string caption)
        {
            try
            {
                MainRibbonForm.Cursor = Cursors.WaitCursor;
                frm.Text = caption;
                frm.MdiParent = MainRibbonForm;
                var f = frm as RibbonForm; if (f != null)
                {
                    f.Ribbon.AllowMinimizeRibbon = true;
                    f.Ribbon.ShowExpandCollapseButton = DevExpress.Utils.DefaultBoolean.True;
                    f.Ribbon.Minimized = true;
                    //f.Ribbon.ApplicationIcon = Program.icoWinform.ToBitmap();
                }
                frm.Show();
                MainRibbonForm.Cursor = Cursors.Default;
            }
            catch (Exception e)
            {

            }
        }
    }
}


 

program.cs代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    static class Program
    {
        /// 
        /// 应用程序的主入口点。
        /// 
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new RibbonForm1());
        }
    }
}

 好了,我们调试一下:

点击navBarItem1:


 

看到已经在导航栏右边显示了ribbonForm2,我们在代码里给它在这里打开时重命名:“新开的窗口”。

你可能感兴趣的:(Devperience,12.1,C#)