CSharp_DevExpress_XtraLayout布局简单实现;

=>效果

CSharp_DevExpress_XtraLayout布局简单实现;_第1张图片


=>源码

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraLayout;
using DevExpress.XtraGrid;

namespace HelloWorld
{
    public partial class XtraForm_XtraLayout : XtraForm
    {
        public XtraForm_XtraLayout()
        {
            InitializeComponent();
        }


        private void XtraForm_XtraLayout_Load(object sender, EventArgs e)
        {
            //流程:LayoutControl->TabbedControlGroup->LayoutControlGroup->LayoutControlItem

            // 创建布局管理器并添加进窗口
            LayoutControl formLCtrl = new LayoutControl()
            {
                Dock = DockStyle.Fill /* 位置;*/
            };
            Controls.Add(formLCtrl);

            // 锁住布局管理器以防过多更新
            formLCtrl.BeginUpdate();
            try
            {
                // TabbedControlGroup_Create a tabbed group within the root group;
                TabbedControlGroup tabbedGroup = formLCtrl.Root.AddTabbedGroup();
                tabbedGroup.Name = "TabbedCtrlGroup";

                // LayoutControlGroup_Add a new group as a tab to the tabbed group;
                LayoutControlGroup groupFirst = tabbedGroup.AddTabPage() as LayoutControlGroup;
                groupFirst.Name = "LayoutControlGroupFirst";
                groupFirst.Text = "Photo";
                // LayoutControlItem_Add a new layout item to the group that will display an image;
                using (LayoutControlItem itemFirst = groupFirst.AddItem())
                {
                    itemFirst.Name = "LayoutControlItemFirst";
                    itemFirst.Control = new PictureEdit();
                    itemFirst.TextVisible = false;
                }  // Hide the item's text region;

                // LayoutControlGroup_Add a new group to the tabbed group;
                LayoutControlGroup groupSecond = tabbedGroup.AddTabPage() as LayoutControlGroup;
                groupSecond.Name = "LayoutControlGroupSecond";
                groupSecond.Text = "Notes";
                using (LayoutControlItem itemSecond = groupSecond.AddItem())
                {
                    itemSecond.Name = "LayoutControlItemSecond";
                    itemSecond.Control = new GridControl();
                    itemSecond.TextVisible = false;
                }

                // Make the first tab page active.
                tabbedGroup.SelectedTabPage = groupSecond;
            }
            finally
            {
                // 解锁并更新布局管理器
                formLCtrl.EndUpdate();
            }

        }
    }
}


你可能感兴趣的:(CSharp)