2 // System.Windows.Forms.Design.DockEditor.cs
5 // Gert Driesen (drieseng@users.sourceforge.net)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.ComponentModel;
32 using System.Drawing.Design;
34 namespace System.Windows.Forms.Design
36 public sealed class DockEditor : UITypeEditor
43 public override object EditValue (ITypeDescriptorContext context, IServiceProvider provider, object value)
45 if (context != null && provider != null)
47 IWindowsFormsEditorService editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
48 if (editorService != null)
50 // Create the UI editor control
51 DockEditorControl dockEditorControl = new DockEditorControl(editorService);
52 dockEditorControl.DockStyle = (DockStyle)context.Instance;
53 editorService.DropDownControl(dockEditorControl);
55 return dockEditorControl.DockStyle;
58 return base.EditValue(context, provider, value);
61 public override UITypeEditorEditStyle GetEditStyle (ITypeDescriptorContext context)
63 return UITypeEditorEditStyle.DropDown;
65 private class DockEditorControl : System.Windows.Forms.UserControl
\r
67 private System.Windows.Forms.CheckBox buttonNone;
\r
68 private System.Windows.Forms.Panel panel1;
\r
69 private System.Windows.Forms.CheckBox buttonBottom;
\r
70 private System.Windows.Forms.CheckBox buttonTop;
\r
71 private System.Windows.Forms.Panel panel2;
\r
72 private System.Windows.Forms.CheckBox buttonLeft;
\r
73 private System.Windows.Forms.CheckBox buttonRight;
\r
74 private System.Windows.Forms.CheckBox buttonFill;
\r
75 private IWindowsFormsEditorService editorService;
\r
76 private DockStyle dockStyle;
\r
78 public DockEditorControl(IWindowsFormsEditorService editorService)
\r
80 buttonNone = new System.Windows.Forms.CheckBox();
\r
81 panel1 = new System.Windows.Forms.Panel();
\r
82 buttonBottom = new System.Windows.Forms.CheckBox();
\r
83 buttonTop = new System.Windows.Forms.CheckBox();
\r
84 panel2 = new System.Windows.Forms.Panel();
\r
85 buttonLeft = new System.Windows.Forms.CheckBox();
\r
86 buttonRight = new System.Windows.Forms.CheckBox();
\r
87 buttonFill = new System.Windows.Forms.CheckBox();
\r
88 panel1.SuspendLayout();
\r
89 panel2.SuspendLayout();
\r
92 buttonNone.Appearance = Appearance.Button;
\r
93 buttonNone.Dock = System.Windows.Forms.DockStyle.Bottom;
\r
94 buttonNone.Location = new System.Drawing.Point(0, 92);
\r
95 buttonNone.Size = new System.Drawing.Size(150, 23);
\r
96 buttonNone.TabIndex = 5;
\r
97 buttonNone.Text = "None";
\r
98 buttonNone.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
\r
99 buttonNone.Click += new System.EventHandler(buttonClick);
\r
101 panel1.Controls.Add(panel2);
\r
102 panel1.Controls.Add(buttonTop);
\r
103 panel1.Controls.Add(buttonBottom);
\r
104 panel1.Dock = System.Windows.Forms.DockStyle.Fill;
\r
105 panel1.Location = new System.Drawing.Point(0, 0);
\r
106 panel1.Name = "panel1";
\r
107 panel1.Size = new System.Drawing.Size(150, 92);
\r
108 panel1.TabStop = false;
\r
110 buttonBottom.Appearance = Appearance.Button;
\r
111 buttonBottom.Dock = System.Windows.Forms.DockStyle.Bottom;
\r
112 buttonBottom.Location = new System.Drawing.Point(0, 69);
\r
113 buttonBottom.Name = "buttonBottom";
\r
114 buttonBottom.Size = new System.Drawing.Size(150, 23);
\r
115 buttonBottom.TabIndex = 5;
\r
116 buttonBottom.Click += new System.EventHandler(buttonClick);
\r
118 buttonTop.Appearance = Appearance.Button;
\r
119 buttonTop.Dock = System.Windows.Forms.DockStyle.Top;
\r
120 buttonTop.Location = new System.Drawing.Point(0, 0);
\r
121 buttonTop.Name = "buttonTop";
\r
122 buttonTop.Size = new System.Drawing.Size(150, 23);
\r
123 buttonTop.TabIndex = 1;
\r
124 buttonTop.Click += new System.EventHandler(buttonClick);
\r
126 panel2.Controls.Add(buttonFill);
\r
127 panel2.Controls.Add(buttonRight);
\r
128 panel2.Controls.Add(buttonLeft);
\r
129 panel2.Dock = System.Windows.Forms.DockStyle.Fill;
\r
130 panel2.Location = new System.Drawing.Point(0, 23);
\r
131 panel2.Size = new System.Drawing.Size(150, 46);
\r
132 panel2.TabIndex = 2;
\r
133 panel2.TabStop = false;
\r
135 buttonLeft.Appearance = Appearance.Button;
\r
136 buttonLeft.Dock = System.Windows.Forms.DockStyle.Left;
\r
137 buttonLeft.Location = new System.Drawing.Point(0, 0);
\r
138 buttonLeft.Size = new System.Drawing.Size(24, 46);
\r
139 buttonLeft.TabIndex = 2;
\r
140 buttonLeft.Click += new System.EventHandler(buttonClick);
\r
142 buttonRight.Appearance = Appearance.Button;
\r
143 buttonRight.Dock = System.Windows.Forms.DockStyle.Right;
\r
144 buttonRight.Location = new System.Drawing.Point(126, 0);
\r
145 buttonRight.Size = new System.Drawing.Size(24, 46);
\r
146 buttonRight.TabIndex = 4;
\r
147 buttonRight.Click += new System.EventHandler(buttonClick);
\r
149 buttonFill.Appearance = Appearance.Button;
\r
150 buttonFill.Dock = System.Windows.Forms.DockStyle.Fill;
\r
151 buttonFill.Location = new System.Drawing.Point(24, 0);
\r
152 buttonFill.Size = new System.Drawing.Size(102, 46);
\r
153 buttonFill.TabIndex = 3;
\r
154 buttonFill.Click += new System.EventHandler(buttonClick);
\r
156 Controls.Add(panel1);
\r
157 Controls.Add(buttonNone);
\r
158 Size = new System.Drawing.Size(150, 115);
\r
159 panel1.ResumeLayout(false);
\r
160 panel2.ResumeLayout(false);
\r
161 ResumeLayout(false);
\r
164 this.editorService = editorService;
\r
165 dockStyle = DockStyle.None;
\r
169 private void buttonClick(object sender, System.EventArgs e)
\r
171 if (sender == buttonNone)
\r
172 dockStyle = DockStyle.None;
\r
173 else if (sender == buttonFill)
\r
174 dockStyle = DockStyle.Fill;
\r
175 else if (sender == buttonLeft)
\r
176 dockStyle = DockStyle.Left;
\r
177 else if (sender == buttonRight)
\r
178 dockStyle = DockStyle.Right;
\r
179 else if (sender == buttonTop)
\r
180 dockStyle = DockStyle.Top;
\r
181 else if (sender == buttonBottom)
\r
182 dockStyle = DockStyle.Bottom;
\r
183 editorService.CloseDropDown();
\r
187 public DockStyle DockStyle
\r
196 buttonNone.Checked = false;
\r
197 buttonBottom.Checked = false;
\r
198 buttonTop.Checked = false;
\r
199 buttonLeft.Checked = false;
\r
200 buttonRight.Checked = false;
\r
201 buttonFill.Checked = false;
\r
204 case DockStyle.Fill:
\r
205 buttonFill.CheckState = CheckState.Checked;
\r
207 case DockStyle.None:
\r
208 buttonNone.CheckState = CheckState.Checked;
\r
210 case DockStyle.Left:
\r
211 buttonLeft.CheckState = CheckState.Checked;
\r
213 case DockStyle.Right:
\r
214 buttonRight.CheckState = CheckState.Checked;
\r
216 case DockStyle.Top:
\r
217 buttonTop.CheckState = CheckState.Checked;
\r
219 case DockStyle.Bottom:
\r
220 buttonBottom.CheckState = CheckState.Checked;
\r