コード例 #1
0
ファイル: UIEditForm.cs プロジェクト: halfmoon2014/localtest
        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;
        }
コード例 #2
0
        private void InitEditor()
        {
            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(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;

                Control ctrl = null;

                if (info.EditType == EditType.Text)
                {
                    ctrl = new UITextBox();
                    var edit = (UITextBox)ctrl;
                    edit.Text       = info.Value?.ToString();
                    edit.EnterAsTab = true;
                }

                if (info.EditType == EditType.Password)
                {
                    ctrl = new UITextBox();
                    var edit = (UITextBox)ctrl;
                    edit.Text         = info.Value?.ToString();
                    edit.PasswordChar = '*';
                    edit.EnterAsTab   = true;
                }

                if (info.EditType == EditType.Integer)
                {
                    ctrl = new UITextBox();
                    var edit = (UITextBox)ctrl;
                    edit.Type       = UITextBox.UIEditType.Integer;
                    edit.IntValue   = info.Value.ToString().ToInt();
                    edit.EnterAsTab = true;
                }

                if (info.EditType == EditType.Double)
                {
                    ctrl = new UITextBox();
                    var edit = (UITextBox)ctrl;
                    edit.Type        = UITextBox.UIEditType.Double;
                    edit.DoubleValue = info.Value.ToString().ToDouble();
                    edit.EnterAsTab  = true;
                }

                if (info.EditType == EditType.Date)
                {
                    ctrl = new UIDatePicker();
                    var edit = (UIDatePicker)ctrl;
                    edit.Value = (DateTime)info.Value;
                }

                if (info.EditType == EditType.DateTime)
                {
                    ctrl = new UIDatetimePicker();
                    var edit = (UIDatetimePicker)ctrl;
                    edit.Value = (DateTime)info.Value;
                }

                if (info.EditType == EditType.Switch)
                {
                    ctrl = new UISwitch();
                    var edit = (UISwitch)ctrl;
                    edit.SwitchShape = UISwitch.UISwitchShape.Square;
                    edit.Height      = 29;
                    edit.Active      = (bool)info.Value;

                    if (info.DataSource != null)
                    {
                        string[] items = (string[])info.DataSource;
                        edit.ActiveText   = items[0];
                        edit.InActiveText = items[1];
                        SizeF sf1 = GDI.MeasureString(items[0], edit.Font);
                        SizeF sf2 = GDI.MeasureString(items[0], edit.Font);
                        edit.Width = (int)Math.Max(sf1.Width, sf2.Width) + edit.Height + 16;
                    }
                }

                if (info.EditType == EditType.Combobox)
                {
                    ctrl = new UIComboBox();
                    var edit = (UIComboBox)ctrl;
                    edit.DropDownStyle = UIDropDownStyle.DropDownList;

                    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;
                    }
                }

                if (info.EditType == EditType.ComboTreeView)
                {
                    ctrl = new UIComboTreeView();
                    var edit = (UIComboTreeView)ctrl;
                    edit.CanSelectRootNode = true;
                    edit.ShowLines         = true;
                    edit.DropDownStyle     = UIDropDownStyle.DropDownList;
                    edit.TreeView.Nodes.Clear();
                    edit.TreeView.Nodes.AddRange((TreeNode[])info.DataSource);
                    if (info.Value != null)
                    {
                        edit.TreeView.SelectedNode = (TreeNode)info.Value;
                        edit.Text = edit.TreeView.SelectedNode.Text;
                    }
                }

                if (info.EditType == EditType.ComboCheckedListBox)
                {
                    ctrl = new UIComboTreeView();
                    var edit = (UIComboTreeView)ctrl;
                    edit.CanSelectRootNode = true;
                    edit.CheckBoxes        = true;
                    edit.DropDownStyle     = UIDropDownStyle.DropDownList;
                    edit.TreeView.Nodes.Clear();
                    edit.Text = info.Value?.ToString();
                    var obj = (ComboCheckedListBoxItem[])info.DataSource;
                    foreach (var item in obj)
                    {
                        TreeNode node = edit.TreeView.Nodes.Add(item.Text);
                        node.Tag     = item;
                        node.Checked = item.Checked;
                    }
                }

                if (ctrl != null)
                {
                    ctrl.Left = Option.LabelWidth;
                    if (info.EditType != EditType.Switch)
                    {
                        ctrl.Width = info.HalfWidth ? Option.ValueWidth / 2 : Option.ValueWidth;
                    }
                    ctrl.Top     = top;
                    ctrl.Parent  = this;
                    ctrl.Name    = "Edit_" + info.DataPropertyName;
                    ctrl.Enabled = info.Enabled;
                    ctrls.Add(ctrl);
                }

                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;
        }
コード例 #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 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;
        }