예제 #1
0
        public static BaseForm CreateOKCancel(string text, BaseAcceptableViewModel viewModel, params FormBuilderItem[] items)
        {
            var form = new BaseForm();

            form.Text       = text;
            form.ClientSize = new Size(100, 80);

            var okCancel = new OKCancelButtons();

            okCancel.Bind(viewModel, form);

            form.AcceptButton = okCancel.OK;
            form.CancelButton = okCancel.Cancel;

            var lc = new LayoutControl();

            lc.Dock = DockStyle.Fill;
            lc.AllowCustomization = false;
            form.Controls.Add(lc);

            lc.BeginUpdate();
            try
            {
                int i = 0;
                foreach (var item in items)
                {
                    var editor = item.Control;
                    var label  = item.Label;

                    var editorItem = lc.Root.AddItem();
                    editorItem.Control = editor;
                    editorItem.Name    = "editorItem" + i++;
                    if (string.IsNullOrEmpty(label))
                    {
                        editorItem.TextVisible = false;
                    }
                    else
                    {
                        editorItem.Text         = label;
                        editorItem.TextLocation = Locations.Top;
                    }
                }

                var okCancelItem = lc.Root.AddItem();
                okCancelItem.Control     = okCancel;
                okCancelItem.Name        = "OKCancel";
                okCancelItem.TextVisible = false;
            }
            finally
            {
                lc.EndUpdate();
            }

            var size = lc.GetPreferredSize(Size.Empty);

            form.ClientSize  = lc.GetPreferredSize(size);
            form.MinimumSize = form.Size;
            return(form);
        }
        protected override void ApplyFocusedStyle(object control)
        {
            LayoutControl layoutControl = control as LayoutControl;

            if (layoutControl != null)
            {
                layoutControl.BeginUpdate();
                layoutControl.OptionsView.HighlightFocusedItem = true;
                layoutControl.OptionsView.AllowItemSkinning    = true;
                layoutControl.EndUpdate();
            }
        }
예제 #3
0
 public static void DoInBatch(this LayoutControl layoutControl, Action action)
 {
     try
     {
         layoutControl.BeginUpdate();
         action();
     }
     finally
     {
         layoutControl.EndUpdate();
     }
 }
        private void CreateLayoutItems(LayoutControl layout)
        {
            layout.BeginUpdate();
            try
            {
                layout.Clear();
                IList <DocumentItemBase> documentItems = GetSortedDocumentItems();
                if (documentItems.Count != 0)
                {
                    int itemsPerRow           = DefaultItemsPerRow;
                    ItemsPerRowAttribute attr = MemberInfo.FindAttribute <ItemsPerRowAttribute>();
                    if (attr != null)
                    {
                        itemsPerRow = attr.Value;
                    }



                    for (int rowNumber = 0; rowNumber < Math.Ceiling((decimal)documentItems.Count / (decimal)itemsPerRow); rowNumber++)
                    {
                        LayoutControlGroup row = layout.AddGroup();
                        row.Name = GetId("Row", rowNumber);
                        row.DefaultLayoutType   = DevExpress.XtraLayout.Utils.LayoutType.Horizontal;
                        row.GroupBordersVisible = false;

                        for (int cellNumber = 0; cellNumber < itemsPerRow; cellNumber++)
                        {
                            if (rowNumber * itemsPerRow + cellNumber < documentItems.Count)
                            {
                                DocumentItemBase  item = documentItems[rowNumber * itemsPerRow + cellNumber];
                                LayoutControlItem cell = new LayoutControlItem(layout, CreateDocumentItemEditor(item));
                                cell.Name = GetId("Cell", item);
                                cell.Text = item.Caption;
                                if (application.Model.Options.LayoutManagerOptions.EnableCaptionColon)
                                {
                                    cell.Text += ":";
                                }
                                row.Add(cell);
                            }
                            else
                            {
                                row.Add(new EmptySpaceItem());
                            }
                        }
                    }
                }
            }
            finally
            {
                layout.EndUpdate();
                layout.BestFit();
            }
        }
 public void InitScrollingInLayout(LayoutControlItem item)
 {
     if (item.Control == this)
     {
         LayoutControl layout = Parent as LayoutControl;
         layout.BeginUpdate();
         layout.Controls.Remove(this);
         layout.Controls.Add(ScrollableContainer);
         item.Control = ScrollableContainer;
         ScrollableContainer.Controls.Add(this);
         layout.EndUpdate();
         Dock = DockStyle.Top;
         UpdateGridHeight();
         ScrollableContainer.Resize += new EventHandler(ScrollableContainer_Resize);
     }
 }
예제 #6
0
        private void CreateLayoutItems()
        {
            layoutControl.BeginUpdate();
            try {
                searchEdit                   = new MRUEdit();
                searchEdit.Name              = "searchEdit";
                searchEdit.EditValueChanged += OnSearchTextChanged;
                LayoutControlItem searchEditItem = layoutControl.AddItem("SearchEditItem", searchEdit);
                searchEditItem.TextVisible = false;
                searchEditItem.Name        = "searchEditItem";

                closeButton             = new SimpleButton();
                closeButton.MaximumSize = new Size(25, closeButton.Height);
                closeButton.Text        = "X";
                closeButton.Name        = "closeButton";
                closeButton.Click      += OnCloseButtonClick;
                closeItem = layoutControl.AddItem("CloseItem", closeButton, searchEditItem,
                                                  DevExpress.XtraLayout.Utils.InsertType.Left);
                closeItem.TextVisible = false;
                closeItem.Name        = "closeItem";

                findButton             = new SimpleButton();
                findButton.MaximumSize = new Size(50, findButton.Height);
                findButton.Text        = "Find";
                findButton.Name        = "findButton";
                findButton.Click      += OnFindButtonClick;
                LayoutControlItem findItem = layoutControl.AddItem("FindItem", findButton, searchEditItem,
                                                                   DevExpress.XtraLayout.Utils.InsertType.Right);
                findItem.TextVisible = false;
                findItem.Name        = "findItem";

                clearButton             = new SimpleButton();
                clearButton.MaximumSize = new Size(50, clearButton.Height);
                clearButton.Text        = "Clear";
                clearButton.Name        = "clearButton";
                clearButton.Click      += OnClearButtonClick;
                LayoutControlItem clearItem = layoutControl.AddItem("ClearItem", clearButton, findItem,
                                                                    DevExpress.XtraLayout.Utils.InsertType.Right);
                clearItem.TextVisible = false;
                clearItem.Name        = "clearItem";
            }
            finally {
                layoutControl.EndUpdate();
            }
        }
예제 #7
0
        void View_ControlsCreated(object sender, EventArgs e)
        {
            LayoutControl layoutControl = ((LayoutControl)((DetailView)View).Control);

            layoutControl.BeginUpdate();
            try
            {
                foreach (object item in layoutControl.Items)
                {
                    if (item is LayoutControlGroup)
                    {
                        ((LayoutControlGroup)item).ExpandButtonVisible   = true;
                        ((LayoutControlGroup)item).Expanded              = true;
                        ((LayoutControlGroup)item).HeaderButtonsLocation = DevExpress.Utils.GroupElementLocation.AfterText;
                        ((LayoutControlGroup)item).ExpandOnDoubleClick   = true;
                    }
                }
            }
            finally
            {
                layoutControl.EndUpdate();
            }
        }
예제 #8
0
        private static void SetLayoutXml(this LayoutControl layoutControl, string xml)
        {
            using (var stream = new MemoryStream())
            {
                using (var writer = new StreamWriter(stream))
                {
                    layoutControl.BeginInit();
                    layoutControl.BeginUpdate();
                    try
                    {
                        writer.Write(xml);
                        writer.Flush();
                        stream.Seek(0, SeekOrigin.Begin);

                        layoutControl.RestoreLayoutFromStream(stream);
                    }
                    finally
                    {
                        layoutControl.EndUpdate();
                        layoutControl.EndInit();
                    }
                }
            }
        }
예제 #9
0
        public static void SetFindControlImages(GridControl grid, bool forceAlignment)
        {
            FindControl fControl = null;

            foreach (Control ctrl in grid.Controls)
            {
                fControl = ctrl as FindControl;
                if (fControl != null)
                {
                    break;
                }
            }
            if (fControl != null)
            {
                EditorButton btn = fControl.FindEdit.Properties.Buttons[0];
                btn.Kind    = XtraEditors.Controls.ButtonPredefines.Search;
                btn         = new EditorButton(ButtonPredefines.Close);
                btn.Visible = false;
                fControl.FindEdit.Properties.Buttons.Add(btn);
                fControl.FindEdit.ButtonClick += (s, e) =>
                {
                    if (!e.Button.IsDefaultButton)
                    {
                        ButtonEdit edit = s as ButtonEdit;
                        edit.Text = string.Empty;
                    }
                };
                fControl.FindEdit.EditValueChanged += (s, e) =>
                {
                    MRUEdit edit = s as MRUEdit;
                    edit.Properties.BeginUpdate();
                    try {
                        edit.Properties.Buttons[0].Visible = string.IsNullOrEmpty(edit.Text);
                        edit.Properties.Buttons[1].Visible = !string.IsNullOrEmpty(edit.Text);
                    }
                    finally {
                        edit.Properties.EndUpdate();
                    }
                };
                if (forceAlignment)
                {
                    LayoutControl lc = fControl.FindEdit.Parent as LayoutControl;
                    lc.BeginUpdate();
                    try {
                        for (int i = lc.Root.Items.Count - 1; i >= 0; i--)
                        {
                            LayoutControlItem item = lc.Root.Items[i] as LayoutControlItem;
                            if (item == null)
                            {
                                continue;
                            }
                            if (item.Visibility == XtraLayout.Utils.LayoutVisibility.Never)
                            {
                                lc.Root.Remove(item);
                            }
                            else
                            {
                                item.ControlAlignment = System.Drawing.ContentAlignment.MiddleRight;
                            }
                        }
                    }
                    finally {
                        lc.EndUpdate();
                    }
                }
            }
        }
예제 #10
0
        private void InitializeQuery()
        {
            List <Sys_Schema> sys_Schemas = InitializeField();

            if (gds.SelectedIndex < 0)
            {
                return;
            }
            GroupControl grid;

            if (gds.EditValue != null && gds.EditValue.GetType() == typeof(GroupControl))
            {
                grid = (GroupControl)gds.EditValue;
                LayoutControl eLayoutControl = (LayoutControl)iDesignerHost.CreateComponent(typeof(LayoutControl), "lyc");
                grid.Controls.Add(eLayoutControl);
                eLayoutControl.BeginUpdate();
                LayoutControlGroup eLayoutControlGroup = new LayoutControlGroup();
                eLayoutControlGroup.BeginUpdate();
                eLayoutControl.Dock     = System.Windows.Forms.DockStyle.Fill;
                eLayoutControl.Location = new System.Drawing.Point(2, 21);
                eLayoutControl.Name     = "eLayoutControl";
                eLayoutControl.Root     = eLayoutControlGroup;
                eLayoutControl.Size     = new System.Drawing.Size(1000, 500);
                eLayoutControl.TabIndex = 0;
                eLayoutControl.Text     = "QueryLayout";
                eLayoutControlGroup.EnableIndentsWithoutBorders = DevExpress.Utils.DefaultBoolean.True;
                eLayoutControlGroup.GroupBordersVisible         = false;
                eLayoutControlGroup.Size        = new Size(1000, 500);
                eLayoutControlGroup.Location    = new Point(0, 0);
                eLayoutControlGroup.Name        = "eLayoutControlGroup";
                eLayoutControlGroup.TextVisible = false;
                List <BaseLayoutItem> baseLayoutItems = new List <BaseLayoutItem>();
                int curLeft = 0;
                int curTop  = 0;
                foreach (Sys_Schema sys_Schema in sys_Schemas)
                {
                    try
                    {
                        string   gn       = string.Format("f{0}", sys_Schema.FieldName);
                        BaseEdit baseEdit = null;
                        if (sys_Schema.SqlDbType.Equals("bit"))
                        {
                            baseEdit      = (CheckEdit)iDesignerHost.CreateComponent(typeof(CheckEdit), gn);
                            baseEdit.Text = string.Empty;
                        }
                        else if (sys_Schema.SqlDbType.Equals("datetime"))
                        {
                            baseEdit = (DateEdit)iDesignerHost.CreateComponent(typeof(DateEdit), gn);
                        }
                        else
                        {
                            baseEdit = (TextEdit)iDesignerHost.CreateComponent(typeof(TextEdit), gn);
                        }
                        baseEdit.Width = 250;
                        baseEdit.Properties.Appearance.Options.UseTextOptions = true;
                        LayoutControlItem eLayoutControlItem = new LayoutControlItem();
                        eLayoutControlItem.Location = new System.Drawing.Point(curLeft, curTop);
                        eLayoutControlItem.Name     = "oli_" + sys_Schema.FieldName;
                        eLayoutControlItem.Text     = sys_Schema.Description;
                        eLayoutControlItem.Size     = new Size(baseEdit.Width, baseEdit.Height);
                        eLayoutControlItem.Control  = baseEdit;
                        baseLayoutItems.Add(eLayoutControlItem);
                        curLeft += baseEdit.Width;
                        if (curLeft >= eLayoutControlGroup.Width)
                        {
                            curLeft = 0;
                            curTop += baseEdit.Height;
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                if (curLeft < eLayoutControlGroup.Width && curLeft > 0)
                {
                    EmptySpaceItem emptySpaceItem = new EmptySpaceItem();
                    emptySpaceItem.AllowHotTrack = false;
                    emptySpaceItem.Location      = new System.Drawing.Point(curLeft, curTop);
                    emptySpaceItem.Name          = "oli_Space";
                    emptySpaceItem.Size          = new System.Drawing.Size(eLayoutControlGroup.Width - curLeft, 24);
                    baseLayoutItems.Add(emptySpaceItem);
                }
                EmptySpaceItem emptyBottom = new EmptySpaceItem();
                emptyBottom.AllowHotTrack = false;
                emptyBottom.Location      = new System.Drawing.Point(0, curTop + 24);
                emptyBottom.Name          = "oli_Space";
                emptyBottom.Size          = new System.Drawing.Size(eLayoutControlGroup.Width, 24);
                baseLayoutItems.Add(emptyBottom);
                eLayoutControlGroup.Items.AddRange(baseLayoutItems.ToArray());
                eLayoutControlGroup.EndUpdate();
                eLayoutControl.EndUpdate();
            }
        }
예제 #11
0
 public void ValidateLayout()
 {
     LayoutControl.Validate();
     LayoutControl.BeginUpdate();
     LayoutControl.EndUpdate();
 }
예제 #12
0
        private void InitializeQuery()
        {
            try
            {
                if (this.QueryControl == null)
                {
                    return;
                }
                this.QueryControl.DoubleClick += QueryAutoClear;
                this.QueryControl.Controls.Clear();
                this.Width = 1024;
                this.QueryControl.Width = 1024;
                LayoutControl eLayoutControl = new LayoutControl();
                eLayoutControl.BeginUpdate();
                eLayoutControl.AllowCustomization = false;
                LayoutControlGroup eLayoutControlGroup = new LayoutControlGroup();
                eLayoutControl.Dock     = System.Windows.Forms.DockStyle.Fill;
                eLayoutControl.Location = new System.Drawing.Point(2, 21);
                eLayoutControl.Name     = "eLayoutControl";
                eLayoutControl.Root     = eLayoutControlGroup;
                eLayoutControl.Size     = new System.Drawing.Size(1000, 90);
                eLayoutControl.TabIndex = 0;
                eLayoutControl.Text     = "QueryLayout";
                eLayoutControlGroup.EnableIndentsWithoutBorders = DevExpress.Utils.DefaultBoolean.True;
                eLayoutControlGroup.GroupBordersVisible         = false;
                eLayoutControlGroup.Location    = new Point(0, 0);
                eLayoutControlGroup.Name        = "eLayoutControlGroup";
                eLayoutControlGroup.Size        = new Size(1000, 90);
                eLayoutControlGroup.TextVisible = false;
                this.QueryControl.Controls.Add(eLayoutControl);
                List <BaseLayoutItem> baseLayoutItems = new List <BaseLayoutItem>();
                List <string>         baseControls    = new List <string>();
                int curLeft = 0;
                int curTop  = 0;
                foreach (Sys_Bind sys_Bind in BindList.Where(b => b.Bind_Name.StartsWith("@") &&
                                                             !string.IsNullOrEmpty(b.Bind_Field) &&
                                                             !b.Bind_Field.Contains(".") &&
                                                             WorkSetList.Find(w => w.WorkSet_Id == b.Bind_WorkSet &&
                                                                              (w.WorkSet_Type == (int)Sys_WorkSet_Type.Submit ||
                                                                               w.WorkSet_Type == (int)Sys_WorkSet_Type.Grid ||
                                                                               w.WorkSet_Type == (int)Sys_WorkSet_Type.Tree)) != null).OrderBy(b => b.Bind_Sort))
                {
                    if (baseControls.Contains(sys_Bind.Bind_Field))
                    {
                        continue;
                    }
                    baseControls.Add(sys_Bind.Bind_Field);
                    sys_Bind.Bind_Type = 0; //查询字段
                    //界面已有控件不再生成
                    Control[] Controls = this.Controls.Find(sys_Bind.Bind_Field, true);
                    if (Controls.Length > 0)
                    {
                        if (!string.IsNullOrEmpty(sys_Bind.Bind_Popup))
                        {
                            BaseEdit cBaseEdit = (BaseEdit)Controls[0];
                            InitializeBaseEdit(sys_Bind, cBaseEdit);
                        }
                        continue;
                    }
                    BaseEdit baseEdit = InitializeBaseEdit(sys_Bind, null);
                    baseEdit.Name = sys_Bind.Bind_Field;
                    if (!string.IsNullOrEmpty(sys_Bind.Bind_Default))
                    {
                        object obj = sys_Bind.Bind_Default;
                        if (obj.ToString().StartsWith("wk:"))
                        {
                            obj = BaseService.Get(obj.ToString().Replace("wk:", ""), null);
                        }
                        ReflectionHelper.SetProperty(baseEdit, string.IsNullOrEmpty(sys_Bind.Bind_Property) ? "EditValue" : sys_Bind.Bind_Property, obj);
                        //baseEdit.EditValue = sys_Bind.Bind_Default;
                        if (baseEdit.GetType().Equals(typeof(CheckEdit)))
                        {
                            CheckEdit chkEdit = (CheckEdit)baseEdit;
                            chkEdit.Text    = string.Empty;
                            chkEdit.Checked = obj.ToBoolEx();
                        }
                    }


                    if (baseEdit.GetType().Equals(typeof(CheckedComboBoxEdit)))
                    {
                        CheckedComboBoxEdit chkComboBox = (CheckedComboBoxEdit)baseEdit;
                        chkComboBox.RefreshEditValue();
                    }
                    baseEdit.EnterMoveNextControl = true;
                    baseEdit.Width = (int)Math.Round(eLayoutControlGroup.Width * (sys_Bind.Bind_Width / 100.00));
                    baseEdit.Properties.Appearance.Options.UseTextOptions = true;
                    baseEdit.Properties.Appearance.TextOptions.HAlignment = (DevExpress.Utils.HorzAlignment)sys_Bind.Bind_TextAlignment;
                    if (sys_Bind.Bind_ForeColor < 0)
                    {
                        baseEdit.ForeColor = Color.FromArgb(sys_Bind.Bind_ForeColor);
                    }
                    if (sys_Bind.Bind_BackColor < 0)
                    {
                        baseEdit.BackColor = Color.FromArgb(sys_Bind.Bind_BackColor);
                    }
                    if (sys_Bind.Bind_BorderColor < 0)
                    {
                        baseEdit.Properties.Appearance.Options.UseBorderColor = true;
                        baseEdit.Properties.Appearance.BorderColor            = Color.FromArgb(sys_Bind.Bind_BorderColor);
                        baseEdit.BorderStyle = BorderStyles.Simple;
                    }
                    baseEdit.ToolTip         = sys_Bind.Bind_ToolTip;
                    baseEdit.ReadOnly        = sys_Bind.Bind_ReadOnly;
                    baseEdit.Visible         = sys_Bind.Bind_Visible;
                    baseEdit.GotFocus       += Control_GotFocus;
                    eLayoutControl.GotFocus += Control_GotFocus;
                    LayoutControlItem eLayoutControlItem = new LayoutControlItem();
                    eLayoutControlItem.Location = new System.Drawing.Point(curLeft, curTop);
                    curLeft += baseEdit.Width;
                    if (curLeft >= eLayoutControlGroup.Width)
                    {
                        curLeft = 0;
                        curTop += baseEdit.Height;
                    }
                    //eLayoutControlItem.Width = (int)Math.Round(eLayoutControl.Width * (sys_Bind.Bind_Width / 100.00));
                    eLayoutControlItem.AppearanceItemCaption.TextOptions.HAlignment = (DevExpress.Utils.HorzAlignment)sys_Bind.Bind_TitleAlignment;
                    eLayoutControlItem.Name       = "oli_" + sys_Bind.Bind_Name;
                    eLayoutControlItem.Text       = sys_Bind.Bind_Nick;
                    eLayoutControlItem.Size       = new Size(baseEdit.Width, baseEdit.Height);
                    eLayoutControlItem.Control    = baseEdit;
                    eLayoutControlItem.Visibility = sys_Bind.Bind_Visible ? DevExpress.XtraLayout.Utils.LayoutVisibility.Always : DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
                    baseLayoutItems.Add(eLayoutControlItem);
                }
                if (curLeft < eLayoutControlGroup.Width && curLeft > 0)
                {
                    EmptySpaceItem emptySpaceItem = new EmptySpaceItem();
                    emptySpaceItem.AllowHotTrack = false;
                    emptySpaceItem.Location      = new System.Drawing.Point(curLeft, curTop);
                    emptySpaceItem.Name          = "oli_Space";
                    emptySpaceItem.Size          = new System.Drawing.Size(eLayoutControlGroup.Width - curLeft, 24);
                    baseLayoutItems.Add(emptySpaceItem);
                }
                eLayoutControlGroup.Items.AddRange(baseLayoutItems.ToArray());
                eLayoutControl.EndUpdate();
            }
            catch (Exception ex)
            {
                SharedFunc.RaiseError(ex);
            }
        }