Esempio n. 1
0
        public UIEditForm(UIEditOption option)
        {
            InitializeComponent();

            btnOK.Text     = UILocalize.OK;
            btnCancel.Text = UILocalize.Cancel;

            Option = option;
            InitEditor();
        }
Esempio n. 2
0
 public static UIEditForm CreateForm(this UIEditOption option)
 {
     return(new UIEditForm(option));
 }
Esempio n. 3
0
        public UIEditForm(UIEditOption option)
        {
            InitializeComponent();

            btnOK.Text     = UILocalize.OK;
            btnCancel.Text = UILocalize.Cancel;

            Option = option;
            if (option == null || option.Infos.Count == 0)
            {
                return;
            }

            base.Text = option.Text;
            int top = 55;

            List <Control> ctrls = new List <Control>();

            if (option.AutoLabelWidth)
            {
                float size = 0;
                foreach (var info in option.Infos)
                {
                    SizeF sf = info.Text.MeasureString(UIFontColor.Font);
                    size = Math.Max(sf.Width, size);
                }

                option.LabelWidth = (int)size + 1 + 50;
            }

            Width = option.LabelWidth + option.ValueWidth + 28;

            foreach (var info in option.Infos)
            {
                UILabel label = new UILabel();
                label.Text      = info.Text;
                label.AutoSize  = false;
                label.Left      = 5;
                label.Width     = option.LabelWidth - 25;
                label.Height    = 29;
                label.Top       = top;
                label.TextAlign = ContentAlignment.MiddleRight;
                label.Parent    = this;

                if (info.EditType == EditType.Text)
                {
                    UITextBox edit = new UITextBox();
                    edit.Left       = option.LabelWidth;
                    edit.Width      = option.ValueWidth;
                    edit.Top        = top;
                    edit.Text       = info.Value?.ToString();
                    edit.Parent     = this;
                    edit.Name       = "Edit_" + info.DataPropertyName;
                    edit.EnterAsTab = true;
                    edit.Enabled    = info.Enabled;
                    ctrls.Add(edit);
                }

                if (info.EditType == EditType.Password)
                {
                    UITextBox edit = new UITextBox();
                    edit.Left         = option.LabelWidth;
                    edit.Width        = option.ValueWidth;
                    edit.Top          = top;
                    edit.Text         = info.Value?.ToString();
                    edit.Parent       = this;
                    edit.PasswordChar = '*';
                    edit.Name         = "Edit_" + info.DataPropertyName;
                    edit.EnterAsTab   = true;
                    edit.Enabled      = info.Enabled;
                    ctrls.Add(edit);
                }

                if (info.EditType == EditType.Integer)
                {
                    UITextBox edit = new UITextBox();
                    edit.Type     = UITextBox.UIEditType.Integer;
                    edit.Left     = option.LabelWidth;
                    edit.Width    = info.HalfWidth ? option.ValueWidth / 2 : option.ValueWidth;
                    edit.Top      = top;
                    edit.IntValue = info.Value.ToString().ToInt();
                    edit.Parent   = this;
                    edit.Name     = "Edit_" + info.DataPropertyName;
                    edit.Enabled  = info.Enabled;
                    ctrls.Add(edit);
                }

                if (info.EditType == EditType.Double)
                {
                    UITextBox edit = new UITextBox();
                    edit.Type        = UITextBox.UIEditType.Double;
                    edit.Left        = option.LabelWidth;
                    edit.Width       = info.HalfWidth ? option.ValueWidth / 2 : option.ValueWidth;
                    edit.Top         = top;
                    edit.DoubleValue = info.Value.ToString().ToDouble();
                    edit.Parent      = this;
                    edit.Name        = "Edit_" + info.DataPropertyName;
                    edit.EnterAsTab  = true;
                    edit.Enabled     = info.Enabled;
                    ctrls.Add(edit);
                }

                if (info.EditType == EditType.Date)
                {
                    UIDatePicker edit = new UIDatePicker();
                    edit.Left    = option.LabelWidth;
                    edit.Width   = info.HalfWidth ? option.ValueWidth / 2 : option.ValueWidth;
                    edit.Top     = top;
                    edit.Value   = (DateTime)info.Value;
                    edit.Parent  = this;
                    edit.Name    = "Edit_" + info.DataPropertyName;
                    edit.Enabled = info.Enabled;
                    ctrls.Add(edit);
                }

                if (info.EditType == EditType.DateTime)
                {
                    UIDatetimePicker edit = new UIDatetimePicker();
                    edit.Left    = option.LabelWidth;
                    edit.Width   = info.HalfWidth ? option.ValueWidth / 2 : option.ValueWidth;
                    edit.Top     = top;
                    edit.Value   = (DateTime)info.Value;
                    edit.Parent  = this;
                    edit.Name    = "Edit_" + info.DataPropertyName;
                    edit.Enabled = info.Enabled;
                    ctrls.Add(edit);
                }

                if (info.EditType == EditType.Switch)
                {
                    UISwitch edit = new UISwitch();
                    edit.SwitchShape = UISwitch.UISwitchShape.Square;
                    edit.Left        = option.LabelWidth - 1;
                    edit.Width       = 75;
                    edit.Height      = 29;
                    edit.Top         = top;
                    edit.Active      = (bool)info.Value;
                    edit.Parent      = this;
                    edit.Name        = "Edit_" + info.DataPropertyName;
                    edit.Enabled     = info.Enabled;
                    ctrls.Add(edit);
                }

                if (info.EditType == EditType.Combobox)
                {
                    UIComboBox edit = new UIComboBox();
                    edit.DropDownStyle = UIDropDownStyle.DropDownList;
                    edit.Left          = option.LabelWidth;
                    edit.Width         = info.HalfWidth ? option.ValueWidth / 2 : option.ValueWidth;
                    edit.Top           = top;
                    edit.Parent        = this;
                    edit.Name          = "Edit_" + info.DataPropertyName;
                    edit.Enabled       = info.Enabled;

                    if (info.DisplayMember.IsNullOrEmpty())
                    {
                        object[] items = (object[])info.DataSource;
                        if (items != null)
                        {
                            edit.Items.AddRange(items);
                            int index = info.Value.ToString().ToInt();
                            if (index < items.Length)
                            {
                                edit.SelectedIndex = index;
                            }
                        }
                    }
                    else
                    {
                        edit.DisplayMember = info.DisplayMember;
                        edit.ValueMember   = info.ValueMember;
                        edit.DataSource    = info.DataSource;
                        edit.SelectedValue = info.Value;
                    }


                    ctrls.Add(edit);
                }

                top += 29 + 10;
            }

            pnlBtm.BringToFront();
            Height = top + 10 + 55;

            int tabIndex = 0;

            foreach (var ctrl in ctrls)
            {
                ctrl.TabIndex = tabIndex;
                tabIndex++;
            }

            pnlBtm.TabIndex = tabIndex;
            tabIndex++;
            btnOK.TabIndex = tabIndex;
            tabIndex++;
            btnCancel.TabIndex  = tabIndex;
            btnOK.ShowFocusLine = btnCancel.ShowFocusLine = true;
        }
Esempio n. 4
0
        public UIEditForm(UIEditOption option)
        {
            InitializeComponent();

            btnOK.Text     = UILocalize.OK;
            btnCancel.Text = UILocalize.Cancel;

            Option = option;
            if (option == null || option.Infos.Count == 0)
            {
                return;
            }

            base.Text = option.Text;
            int tabIndex = 0;
            int top      = 55;

            if (option.AutoLabelWidth)
            {
                float size = 0;
                foreach (var info in option.Infos)
                {
                    SizeF sf = info.Text.MeasureString(UIFontColor.Font);
                    size = Math.Max(sf.Width, size);
                }

                option.LabelWidth = (int)size + 1 + 50;
            }

            Width = option.LabelWidth + option.ValueWidth + 28;

            foreach (var info in option.Infos)
            {
                UILabel label = new UILabel();
                label.Text      = info.Text;
                label.AutoSize  = false;
                label.Left      = 5;
                label.Width     = option.LabelWidth - 25;
                label.Height    = 29;
                label.Top       = top;
                label.TextAlign = ContentAlignment.MiddleRight;
                label.Parent    = this;

                if (info.EditType == EditType.Text)
                {
                    UITextBox edit = new UITextBox();
                    edit.Left     = option.LabelWidth;
                    edit.Width    = option.ValueWidth;
                    edit.Top      = top;
                    edit.Text     = info.Value.ToString();
                    edit.Parent   = this;
                    edit.TabIndex = tabIndex;
                    edit.Name     = "Edit_" + info.DataPropertyName;
                }

                if (info.EditType == EditType.Integer)
                {
                    UITextBox edit = new UITextBox();
                    edit.Type     = UITextBox.UIEditType.Integer;
                    edit.Left     = option.LabelWidth;
                    edit.Width    = info.HalfWidth ? option.ValueWidth / 2 : option.ValueWidth;
                    edit.Top      = top;
                    edit.IntValue = info.Value.ToString().ToInt();
                    edit.Parent   = this;
                    edit.TabIndex = tabIndex;
                    edit.Name     = "Edit_" + info.DataPropertyName;
                }

                if (info.EditType == EditType.Double)
                {
                    UITextBox edit = new UITextBox();
                    edit.Type        = UITextBox.UIEditType.Double;
                    edit.Left        = option.LabelWidth;
                    edit.Width       = info.HalfWidth ? option.ValueWidth / 2 : option.ValueWidth;
                    edit.Top         = top;
                    edit.DoubleValue = info.Value.ToString().ToDouble();
                    edit.Parent      = this;
                    edit.TabIndex    = tabIndex;
                    edit.Name        = "Edit_" + info.DataPropertyName;
                }

                if (info.EditType == EditType.Date)
                {
                    UIDatePicker edit = new UIDatePicker();
                    edit.Left     = option.LabelWidth;
                    edit.Width    = info.HalfWidth ? option.ValueWidth / 2 : option.ValueWidth;
                    edit.Top      = top;
                    edit.Value    = (DateTime)info.Value;
                    edit.Parent   = this;
                    edit.TabIndex = tabIndex;
                    edit.Name     = "Edit_" + info.DataPropertyName;
                }

                if (info.EditType == EditType.DateTime)
                {
                    UIDatetimePicker edit = new UIDatetimePicker();
                    edit.Left     = option.LabelWidth;
                    edit.Width    = info.HalfWidth ? option.ValueWidth / 2 : option.ValueWidth;
                    edit.Top      = top;
                    edit.Value    = (DateTime)info.Value;
                    edit.Parent   = this;
                    edit.TabIndex = tabIndex;
                    edit.Name     = "Edit_" + info.DataPropertyName;
                }

                top += 29 + 10;
                tabIndex++;
            }

            Height = top + 10 + 55;
        }