2 // System.Windows.Forms.Design.AnchorEditor.cs
5 // For creating type editors see the *great* tutorial:
6 // "Walkthrough: implement a UI Type Editor"
10 // Miguel de Icaza (miguel@novell.com)
11 // (C) 2006 Novell, Inc. http://www.ximian.com
14 // Permission is hereby granted, free of charge, to any person obtaining
15 // a copy of this software and associated documentation files (the
16 // "Software"), to deal in the Software without restriction, including
17 // without limitation the rights to use, copy, modify, merge, publish,
18 // distribute, sublicense, and/or sell copies of the Software, and to
19 // permit persons to whom the Software is furnished to do so, subject to
20 // the following conditions:
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 using System
.ComponentModel
;
37 using System
.Drawing
.Design
;
38 using System
.Windows
.Forms
;
40 namespace System
.Windows
.Forms
.Design
42 public sealed class AnchorEditor
: UITypeEditor
44 #region Public Instance Constructors
50 #endregion Public Instance Constructors
52 #region Override implementation of UITypeEditor
54 public override object EditValue(ITypeDescriptorContext context
, IServiceProvider provider
, Object
value)
56 IWindowsFormsEditorService editor_service
= null;
58 if (provider
!= null){
59 editor_service
= provider
.GetService (typeof (IWindowsFormsEditorService
))
60 as IWindowsFormsEditorService
;
63 if (editor_service
!= null){
64 AnchorSelector anchor_selector
= new AnchorSelector (editor_service
, (AnchorStyles
) value);
65 editor_service
.DropDownControl (anchor_selector
);
67 value = anchor_selector
.AnchorStyles
;
73 public override UITypeEditorEditStyle
GetEditStyle(ITypeDescriptorContext context
)
75 return UITypeEditorEditStyle
.DropDown
;
78 #endregion Override implementation of UITypeEditor
81 internal class AnchorSelector
: UserControl
84 /// Required designer variable.
86 private System
.ComponentModel
.IContainer components
= null;
88 protected override void Dispose(bool disposing
)
90 if (disposing
&& (components
!= null)) {
93 base.Dispose(disposing
);
96 private void InitializeComponent()
99 this.Name
= "AnchorSelector";
100 this.Size
= new System
.Drawing
.Size (150, 120);
101 this.ResumeLayout(false);
104 public AnchorStyles AnchorStyles
{
112 public AnchorSelector (IWindowsFormsEditorService editor_service
, AnchorStyles startup
)
116 InitializeComponent();
117 BackColor
= Color
.White
;
120 void PaintState(Graphics g
, int x1
, int y1
, int x2
, int y2
, AnchorStyles v
)
122 if ((styles
& v
) != 0)
123 g
.DrawLine(SystemPens
.MenuText
, x1
, y1
, x2
, y2
);
125 int xf
= (x1
== x2
) ? 10 : 0;
126 int yf
= (y1
== y2
) ? 10 : 0;
128 g
.DrawBezier(SystemPens
.MenuText
,
130 new Point((x1
+x2
)/2+xf
, (y1
+y2
)/2-yf
),
131 new Point((x1
+x2
)/2-xf
, (y1
+y2
)/2+yf
),
136 protected override void OnPaint (PaintEventArgs e
)
138 Graphics g
= e
.Graphics
;
144 g
.FillRectangle(Brushes
.Black
, new Rectangle(w3
, h3
, w3
, h3
));
146 PaintState (g
, 0, h2
, w3
, h2
, AnchorStyles
.Left
);
147 PaintState (g
, w3
* 2, h2
, Width
, h2
, AnchorStyles
.Right
);
148 PaintState (g
, w2
, 0, w2
, h3
, AnchorStyles
.Top
);
149 PaintState (g
, w2
, h3
* 2, w2
, Height
, AnchorStyles
.Bottom
);
152 protected override void OnClick (EventArgs ee
)
154 Point e
= PointToClient (MousePosition
);
158 if (e
.X
<= w3
&& e
.Y
> h3
&& e
.Y
< h3
* 2)
159 styles
= styles ^ AnchorStyles
.Left
;
160 else if (e
.Y
< h3
&& e
.X
> w3
&& e
.X
< w3
* 2)
161 styles
= styles ^ AnchorStyles
.Top
;
162 else if (e
.X
> w3
* 2 && e
.Y
> h3
&& e
.Y
< h3
* 2)
163 styles
= styles ^ AnchorStyles
.Right
;
164 else if (e
.Y
> h3
* 2 && e
.X
> w3
&& e
.X
< w3
* 2)
165 styles
= styles ^ AnchorStyles
.Bottom
;
171 protected override void OnDoubleClick (EventArgs ee
)