/// <summary> /// Constructor /// </summary> public DataGridViewSliderColumn() { CellTemplate = new DataGridViewSliderCell(); _Slider = new Slider(); _Slider.Visible = false; HookEvents(true); }
/* * public void CreateWinControls(Control dockWinControl) * { * dockWinControl.SuspendLayout(); * listWinControls.Clear(); * string type; * foreach (TlControl tlControl in _clmb.listTlControls) * { * Control winControl = null; * type = tlControl.Type; * * if (type == "GroupBox") * { * winControl = new GroupBox(); * winControl.SuspendLayout(); * * ((GroupBox)winControl).ForeColor = ((TlGroupBox)tlControl).ForeColor; * ((GroupBox)winControl).Text = ((TlGroupBox)tlControl).Text; * } * else if (type == "Label") * { * winControl = new Label(); * * ((Label)winControl).ForeColor = ((TlLabel)tlControl).ForeColor; * ((Label)winControl).AutoSize = ((TlLabel)tlControl).AutoSize; * ((Label)winControl).Text = ((TlLabel)tlControl).Text; * } * else if (type == "ComboBox") * { * winControl = new ComboBox(); * * ((ComboBox)winControl).DropDownStyle = (ComboBoxStyle)((TlComboBox)tlControl).DropDownStyle; * ((ComboBox)winControl).Items.AddRange(((TlComboBox)tlControl).ListItems.ToArray()); * * } * else if (type == "TextBox") * { * winControl = new TextBox(); * } * else if (type == "Button") * { * winControl = new Button(); * ((Button)winControl).Text = ((TlButton)tlControl).Text; * } * else if (type == "CheckBox") * { * winControl = new CheckBox(); * * ((CheckBox)winControl).ForeColor = ((TlCheckBox)tlControl).ForeColor; * ((CheckBox)winControl).AutoSize = ((TlCheckBox)tlControl).AutoSize; * ((CheckBox)winControl).Text = ((TlCheckBox)tlControl).Text; * } * else if (type == "ListBox") * { * winControl = new ListBox(); * } * else if (type == "Panel") * { * winControl = new Panel(); * winControl.SuspendLayout(); * } * else if (type == "DateTimePicker") * { * winControl = new DateTimePicker(); * * ((DateTimePicker)winControl).ShowUpDown = ((TlDateTimePicker)tlControl).ShowUpDown; * ((DateTimePicker)winControl).Format = (DateTimePickerFormat)((TlDateTimePicker)tlControl).Format; * ((DateTimePicker)winControl).CustomFormat = ((TlDateTimePicker)tlControl).CustomFormat; * } * * if (winControl != null) * { * winControl.Name = tlControl.Name; * winControl.Location = new Point(tlControl.X, tlControl.Y); * winControl.Size = new Size(tlControl.Width, tlControl.Height); * winControl.TabIndex = tlControl.TabIndex; * winControl.Visible = tlControl.Visable; * winControl.Enabled = tlControl.Enable; * winControl.TabStop = tlControl.TabStop; * winControl.Dock = (DockStyle)tlControl.Dock; * * foreach (TlFont tlFont in listTlFonts) * { * if (tlControl.FontName == tlFont.Name) * { * winControl.Font = new Font(tlFont.FamilyName, tlFont.EmSize, (FontStyle)tlFont.Style); * break; * } * } * * listWinControls.Add(winControl); * * } * } * * //遍历处理控件Controls.Add(); * foreach (Control winControl in listWinControls) * { * foreach (TlControl tlControl in _clmb.listTlControls) * { * if (winControl.Name == tlControl.Name) * { * foreach (Control winParentControl in listWinControls) * { * if (tlControl.TlParentControl == null) * { * if (!dockWinControl.Controls.Contains(winControl)) * { * dockWinControl.Controls.Add(winControl); * } * break; * } * else if (winParentControl.Name == tlControl.TlParentControl.Name) * { * winParentControl.Controls.Add(winControl); * break; * } * } * break; * } * } * } * * * foreach (Control winControl in listWinControls) * { * foreach (TlControl tlControl in _clmb.listTlControls) * { * if (winControl.Name == tlControl.Name) * { * if (tlControl.Type == "Panel" || tlControl.Type == "GroupBox") * { * winControl.ResumeLayout(true); * break; * } * } * } * } * dockWinControl.ResumeLayout(false); * } */ #endregion #region 第2种实现方式, 要求:listTlControlst和listWinControls一一对应,效率更高 public void CreateWinControls(Control dockWinControl) { //dockWinControl.SuspendLayout(); listWinControls.Clear(); string type; for (int i = 0; i < _clmb.listTlControls.Count; i++) { Control winControl = null; type = _clmb.listTlControls[i].Type; if (type == "GroupBox") { winControl = new GroupBox(); //winControl.SuspendLayout(); ((GroupBox)winControl).ForeColor = ((TlGroupBox)_clmb.listTlControls[i]).ForeColor; // ((GroupBox)winControl).Text = ((TlGroupBox)_clmb.listTlControls[i]).Text; } else if (type == "Label") { winControl = new Label(); ((Label)winControl).ForeColor = ((TlLabel)_clmb.listTlControls[i]).ForeColor; ((Label)winControl).AutoSize = ((TlLabel)_clmb.listTlControls[i]).AutoSize; // ((Label)winControl).Text = ((TlLabel)_clmb.listTlControls[i]).Text; } else if (type == "ComboBox") { winControl = new ComboBox(); ((ComboBox)winControl).DropDownStyle = (ComboBoxStyle)((TlComboBox)_clmb.listTlControls[i]).DropDownStyle; ((ComboBox)winControl).Items.AddRange(((TlComboBox)_clmb.listTlControls[i]).ListItems.ToArray()); if (_clmb.listTlControls[i].DicEvents.ContainsKey("SelectedIndexChanged")) { ((ComboBox)winControl).SelectedIndexChanged += new EventHandler(controlEvent_SelectedIndexChanged); } } else if (type == "TextBox") { winControl = new TextBox(); } else if (type == "Button") { winControl = new Button(); } else if (type == "ButtonX") { winControl = new DevComponents.DotNetBar.ButtonX(); if (((TlButtonX)_clmb.listTlControls[i]).Image != "") { ((DevComponents.DotNetBar.ButtonX)winControl).Image = (System.Drawing.Bitmap)(global::TempertureEditor.Properties.Resources.ResourceManager.GetObject(((TlButtonX)_clmb.listTlControls[i]).Image, global::TempertureEditor.Properties.Resources.Culture)); } ((DevComponents.DotNetBar.ButtonX)winControl).AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton; ((DevComponents.DotNetBar.ButtonX)winControl).ColorTable = DevComponents.DotNetBar.eButtonColor.OrangeWithBackground; } else if (type == "PrintPreviewControl") { winControl = new PrintPreviewControl(); ((PrintPreviewControl)winControl).UseAntiAlias = true; ((PrintPreviewControl)winControl).AutoZoom = false; ((PrintPreviewControl)winControl).Zoom = 1D; } else if (type == "CheckBox") { winControl = new CheckBox(); ((CheckBox)winControl).ForeColor = ((TlCheckBox)_clmb.listTlControls[i]).ForeColor; ((CheckBox)winControl).AutoSize = ((TlCheckBox)_clmb.listTlControls[i]).AutoSize; ((CheckBox)winControl).Text = ((TlCheckBox)_clmb.listTlControls[i]).Text; ((CheckBox)winControl).Checked = ((TlCheckBox)_clmb.listTlControls[i]).Checked; ((CheckBox)winControl).CheckedChanged += new EventHandler(controlEvent_CheckedChanged); ((CheckBox)winControl).CheckStateChanged += new EventHandler(controlEvent_CheckStateChanged); } else if (type == "RadioButton") { winControl = new RadioButton(); ((RadioButton)winControl).ForeColor = ((TlRadioButton)_clmb.listTlControls[i]).ForeColor; ((RadioButton)winControl).AutoSize = ((TlRadioButton)_clmb.listTlControls[i]).AutoSize; // ((RadioButton)winControl).Text = ((TlRadioButton)_clmb.listTlControls[i]).Text; ((RadioButton)winControl).UseVisualStyleBackColor = ((TlRadioButton)_clmb.listTlControls[i]).UseVisualStyleBackColor; ((RadioButton)winControl).Checked = ((TlRadioButton)_clmb.listTlControls[i]).Checked; ((RadioButton)winControl).CheckedChanged += new EventHandler(controlEvent_CheckedChanged); } else if (type == "ListBox") { winControl = new ListBox(); } else if (type == "Panel" || type == "PanelControl" || type == "GroupPanel") { if (type == "Panel") { winControl = new Panel(); } else { if (type == "PanelControl") { winControl = new PanelControl(); } else { if (type == "GroupPanel") { winControl = new GroupPanel(); } else { } } #region 未实现配置样式 ((PanelControl)winControl).Style.BackColor2SchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBackground2; ((PanelControl)winControl).Style.BackColorGradientAngle = 90; ((PanelControl)winControl).Style.BackColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBackground; ((PanelControl)winControl).Style.BorderBottom = DevComponents.DotNetBar.eStyleBorderType.Solid; ((PanelControl)winControl).Style.BorderBottomWidth = 1; ((PanelControl)winControl).Style.BorderColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBorder; ((PanelControl)winControl).Style.BorderLeft = DevComponents.DotNetBar.eStyleBorderType.Solid; ((PanelControl)winControl).Style.BorderLeftWidth = 1; ((PanelControl)winControl).Style.BorderRight = DevComponents.DotNetBar.eStyleBorderType.Solid; ((PanelControl)winControl).Style.BorderRightWidth = 1; ((PanelControl)winControl).Style.BorderTop = DevComponents.DotNetBar.eStyleBorderType.Solid; ((PanelControl)winControl).Style.BorderTopWidth = 1; ((PanelControl)winControl).Style.CornerDiameter = 4; ((PanelControl)winControl).Style.CornerType = DevComponents.DotNetBar.eCornerType.Rounded; ((PanelControl)winControl).Style.TextAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Center; ((PanelControl)winControl).Style.TextColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelText; ((PanelControl)winControl).Style.TextLineAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Near; ((PanelControl)winControl).StyleMouseDown.CornerType = DevComponents.DotNetBar.eCornerType.Square; ((PanelControl)winControl).StyleMouseOver.CornerType = DevComponents.DotNetBar.eCornerType.Square; #endregion ((PanelControl)winControl).ShowFocusRectangle = ((TlPanelControl)_clmb.listTlControls[i]).ShowFocusRectangle; ((PanelControl)winControl).ColorSchemeStyle = (eDotNetBarStyle)((TlPanelControl)_clmb.listTlControls[i]).ColorSchemeStyle; ((PanelControl)winControl).CanvasColor = ((TlPanelControl)_clmb.listTlControls[i]).CanvasColor; } ((Panel)winControl).AutoScroll = ((TlPanel)_clmb.listTlControls[i]).AutoScroll; } else if (type == "DateTimePicker") { winControl = new DateTimePicker(); ((DateTimePicker)winControl).ShowUpDown = ((TlDateTimePicker)_clmb.listTlControls[i]).ShowUpDown; ((DateTimePicker)winControl).Format = (DateTimePickerFormat)((TlDateTimePicker)_clmb.listTlControls[i]).Format; ((DateTimePicker)winControl).CustomFormat = ((TlDateTimePicker)_clmb.listTlControls[i]).CustomFormat; if (_clmb.listTlControls[i].DicEvents.ContainsKey("ValueChanged")) { ((DateTimePicker)winControl).ValueChanged += new EventHandler(controlEvent_ValueChanged); } } else if (type == "PictureBox") { winControl = new PictureBox(); ((PictureBox)winControl).BackColor = ((TlPictureBox)_clmb.listTlControls[i]).BackColor; } else if (type == "ExpandableSplitter") { winControl = new DevComponents.DotNetBar.ExpandableSplitter(); ((DevComponents.DotNetBar.ExpandableSplitter)winControl).Style = (DevComponents.DotNetBar.eSplitterStyle)((TlExpandableSplitter)_clmb.listTlControls[i]).Style; } else if (type == "AdvTree") { winControl = new DevComponents.AdvTree.AdvTree(); ((DevComponents.AdvTree.AdvTree)winControl).ForeColor = ((TlAdvTree)_clmb.listTlControls[i]).ForeColor; ((DevComponents.AdvTree.AdvTree)winControl).AllowDrop = ((TlAdvTree)_clmb.listTlControls[i]).AllowDrop; ((DevComponents.AdvTree.AdvTree)winControl).AccessibleRole = System.Windows.Forms.AccessibleRole.Outline; ((DevComponents.AdvTree.AdvTree)winControl).BackgroundStyle.Class = "TreeBorderKey"; ((DevComponents.AdvTree.AdvTree)winControl).BackgroundStyle.CornerType = DevComponents.DotNetBar.eCornerType.Square; ((DevComponents.AdvTree.AdvTree)winControl).NodeSpacing = 2; ((DevComponents.AdvTree.AdvTree)winControl).PathSeparator = ";"; } else if (type == "Slider") { winControl = new DevComponents.DotNetBar.Controls.Slider(); ((DevComponents.DotNetBar.Controls.Slider)winControl).Minimum = ((TlSlider)_clmb.listTlControls[i]).Minimum; ((DevComponents.DotNetBar.Controls.Slider)winControl).Maximum = ((TlSlider)_clmb.listTlControls[i]).Maximum; ((DevComponents.DotNetBar.Controls.Slider)winControl).Value = ((TlSlider)_clmb.listTlControls[i]).Value; ((DevComponents.DotNetBar.Controls.Slider)winControl).BackgroundStyle.CornerType = DevComponents.DotNetBar.eCornerType.Square; ((DevComponents.DotNetBar.Controls.Slider)winControl).Style = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled; } else if (type == "ucAiTemperature") { winControl = new ucAiTemperature(((TlAiTemperature)_clmb.listTlControls[i]).ClmbFileName); } /* * else if (type == "ucTemperatureFrame") * { * winControl = new ucTemperatureFrame(((TlAiTemperature)_clmb.listTlControls[i]).ClmbFileName); * } */ else if (type == "ucTemperatureReport") { winControl = new ucTemperatureReport(((TlTemperatureReport)_clmb.listTlControls[i]).TmbFileName); } else if (type == "RibbonBar") { winControl = new RibbonBar(); ((RibbonBar)winControl).Style = (eDotNetBarStyle)((TlRibbonBar)_clmb.listTlControls[i]).Style; ((RibbonBar)winControl).TitleVisible = ((TlRibbonBar)_clmb.listTlControls[i]).TitleVisible; ((RibbonBar)winControl).AutoOverflowEnabled = ((TlRibbonBar)_clmb.listTlControls[i]).AutoOverflowEnabled; ((RibbonBar)winControl).ContainerControlProcessDialogKey = ((TlRibbonBar)_clmb.listTlControls[i]).ContainerControlProcessDialogKey; } if (winControl != null) { if (_clmb.listTlControls[i].BackColor != null) { winControl.BackColor = (Color)_clmb.listTlControls[i].BackColor; } winControl.Name = _clmb.listTlControls[i].Name; winControl.Location = new Point(_clmb.listTlControls[i].X, _clmb.listTlControls[i].Y); winControl.Size = new Size(_clmb.listTlControls[i].Width, _clmb.listTlControls[i].Height); winControl.TabIndex = _clmb.listTlControls[i].TabIndex; winControl.Visible = _clmb.listTlControls[i].Visable; winControl.Enabled = _clmb.listTlControls[i].Enable; winControl.TabStop = _clmb.listTlControls[i].TabStop; foreach (TlFont tlFont in _clmb.listTlFonts) { if (_clmb.listTlControls[i].FontName == tlFont.Name) { winControl.Font = new Font(tlFont.FamilyName, tlFont.EmSize, (FontStyle)tlFont.Style); break; } } winControl.Dock = (DockStyle)_clmb.listTlControls[i].Dock; winControl.Text = _clmb.listTlControls[i].Text; // 注: 不能使用if/else,因为同个控件可能要处理多个事件 if (_clmb.listTlControls[i].DicEvents.ContainsKey("Click")) { winControl.Click += new EventHandler(controlEvent_Click); } if (_clmb.listTlControls[i].DicEvents.ContainsKey("TextChanged")) { winControl.TextChanged += new EventHandler(controlEvent_TextChanged); } if (_clmb.listTlControls[i].DicEvents.ContainsKey("SizeChanged")) { winControl.SizeChanged += new EventHandler(controlEvent_SizeChanged); } listWinControls.Add(winControl); } } //特殊类型处理,需在所有控件创建后处理 for (int i = 0; i < _clmb.listTlControls.Count; i++) { if (_clmb.listTlControls[i].Type == "ExpandableSplitter") { ((DevComponents.DotNetBar.ExpandableSplitter)listWinControls[i]).ExpandableControl = listWinControls.Find(cl => cl.Name == ((TlExpandableSplitter)_clmb.listTlControls[i]).ExpandableControl); //等同以下注释代码功能 /* * foreach (Control tmpControl in listWinControls) * { * if (tmpControl.Name == ((TlExpandableSplitter)_clmb.listTlControls[i]).ExpandableControl) * { * ((DevComponents.DotNetBar.ExpandableSplitter)listWinControls[i]).ExpandableControl = tmpControl; * break; * } * } */ } /* * if (_clmb.listTlControls[i].Type == "RibbonBar") * { * foreach (string itemName in ((TlRibbonBar)_clmb.listTlControls[i]).ListItems) * { * Control findControl = listWinControls.Find(cl => cl.Name == itemName); * if (findControl != null) * { * // ((RibbonBar)listWinControls[i]).Items.Add((BaseItem)findControl); * * * } * } * } */ } //遍历处理控件Controls.Add(); 当同一DockStyle时,如都为DockStyle.Top时,倒序Add才能按配置文件的正序展示 for (int i = listWinControls.Count - 1; i >= 0; i--) { Control winControl = listWinControls[i]; if (_clmb.listTlControls[i].TlParentControl == null) { if (!dockWinControl.Controls.Contains(winControl)) { dockWinControl.Controls.Add(winControl); } } else { foreach (Control winParentControl in listWinControls) { if (winParentControl.Name == _clmb.listTlControls[i].TlParentControl.Name) { winParentControl.Controls.Add(winControl); break; } } } } /* * for (int i = listWinControls.Count - 1; i >= 0 ; i--) * { * Control winControl = listWinControls[i]; * if (_clmb.listTlControls[i].Type == "Panel" || _clmb.listTlControls[i].Type == "GroupBox") * { * winControl.ResumeLayout(true); * break; * } * } */ //dockWinControl.ResumeLayout(false); }