示例#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);
        }
示例#2
0
 public static ControlCommandBinder[] Bind(this OKCancelButtons button, BaseAcceptableViewModel acceptable, IConfirmCommand cancel = null)
 {
     return(new[]
     {
         Bind(button.GetOK(), acceptable.Accept),
         Bind(button.GetCancel(), acceptable.Cancel, cancel),
     });
 }