Devepress LayoutControl的使用

一个讲述动态创建Devpress LayoutControl控件的使用例子。

通过代码动态添加 LayoutControlItem ,TabbedControlGroup ,LayoutControlGroup 及具体控件并排版的例子。

private void InitLayoutControl()

        {
            LayoutControlItem lci1 = layoutControlGroup.AddItem();
            DateEdit de = new DateEdit();
            lci1.Control = de;
            lci1.Text = "日期:";


            LayoutControlItem lci3 = layoutControlGroup.AddItem();
            lci3.Move(lci1, InsertType.Right);
            lci3.TextVisible = false;


            LayoutControlItem lci2 = layoutControlGroup.AddItem();
            SimpleButton sb = new SimpleButton();
            sb.Text = "确定";
            lci2.Control = sb;
            lci2.TextVisible = false;
            lci2.Move(lci3, InsertType.Right);

            TabbedControlGroup tcg = layoutControl.Root.AddTabbedGroup();

            LayoutControlGroup lcg1 = tcg.AddTabPage("one");
            LayoutControlItem lci11 = lcg1.AddItem();
            lci11.Control = new TextEdit();
            lci11.Text = "First:";
            lci11.AppearanceItemCaption.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Far;
            LayoutControlItem lci12 = lcg1.AddItem();
            lci12.Control = new TextEdit();
            lci12.Text = "Second:";
            LayoutControlItem lci13 = lcg1.AddItem();
            lci13.Control = new TextEdit();
            lci13.Text = "Three:";
            lci13.Move(lci12, InsertType.Right);

            LayoutControlGroup lcg2 = tcg.AddTabPage("two");
            LayoutControlItem lci21 = lcg2.AddItem();
            SimpleButton sb21 = new SimpleButton();
            sb21.Text = "Test";
            sb21.Click += new EventHandler(sb21_Click);
            lci21.Control = sb21;

            LayoutControlGroup lcg3 = tcg.AddTabPage("three");
            LayoutControlItem lci31 = lcg3.AddItem();
            MemoEdit me = new MemoEdit();
            me.Dock = DockStyle.Fill;
            lci31.Control = me;
            lci31.Padding = new DevExpress.XtraLayout.Utils.Padding(0);
            lci31.TextVisible = false;


        }

        void sb21_Click(object sender, EventArgs e)
        {
            foreach (Control c in layoutControl.Controls)
            {
                MessageBox.Show(c.GetType().ToString()+":"+ c.Text);
            }
        }

你可能感兴趣的:(layout)