2 // System.Windows.Forms.GroupBox.cs
5 // stubbed out by Daniel Carrera (dcarrera@math.toronto.edu)
6 // Dennis Hayes (dennish@raytek.com)
7 // Aleksey Ryabchuk (ryabchuk@yahoo.com)
9 // (C) 2002/3 Ximian, Inc
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System
.ComponentModel
;
35 namespace System
.Windows
.Forms
{
38 // Represents a Windows group box.
41 public class GroupBox
: Control
{
47 SetStyle ( ControlStyles
.UserPaint
, true);
48 SetStyle ( ControlStyles
.Selectable
, false );
50 flatStyle
= FlatStyle
.Standard
;
53 [EditorBrowsable (EditorBrowsableState
.Never
)]
54 public override bool AllowDrop
{
55 get { return base.AllowDrop; }
56 set { base.AllowDrop = value; }
60 public override Rectangle DisplayRectangle
{
63 return base.DisplayRectangle
;
68 public FlatStyle FlatStyle
{
69 get { return flatStyle; }
71 if ( !Enum
.IsDefined ( typeof(FlatStyle
), value ) )
72 throw new InvalidEnumArgumentException( "FlatStyle",
79 public override string ToString() {
80 return GetType ( ).FullName
.ToString ( ) + ", Text: " + Text
;
84 protected override CreateParams CreateParams
{
86 RegisterDefaultWindowClass ( );
88 CreateParams createParams
= base.CreateParams
;
89 createParams
.ClassName
= Win32
.DEFAULT_WINDOW_CLASS
;;
91 createParams
.Style
= (int) (
92 (int)WindowStyles
.WS_CHILDWINDOW
|
93 (int)WindowStyles
.WS_CLIPCHILDREN
|
94 (int)WindowStyles
.WS_CLIPSIBLINGS
|
95 (int)WindowStyles
.WS_OVERLAPPED
|
96 (int)WindowStyles
.WS_VISIBLE
);
102 protected override Size DefaultSize
{
103 get { return new Size(200,100); }
107 protected override void OnFontChanged(EventArgs e
) {
108 base.OnFontChanged(e
);
112 public override string Text
{
113 get { return base.Text; }
121 protected override void OnPaint(PaintEventArgs e
) {
123 //FIXME: use TextMetrics to calculate coordinates in the method
124 Rectangle bounds
= DisplayRectangle
;
126 Bitmap bmp
= new Bitmap(bounds
.Width
, bounds
.Height
, e
.Graphics
);
127 Graphics paintOn
= Graphics
.FromImage(bmp
);
129 Brush br
= new SolidBrush(BackColor
);
130 paintOn
.FillRectangle(br
, bounds
);
136 bounds.Inflate(-4,-4);
139 Color dark
= ControlPaint
.DarkDark ( BackColor
);
140 Color light
= ControlPaint
.LightLight ( BackColor
);
142 ControlPaint
.DrawBorder(paintOn
, bounds
, dark
, 1, ButtonBorderStyle
.Solid
,
143 dark
, 1, ButtonBorderStyle
.Solid
, light
, 1, ButtonBorderStyle
.Solid
,
144 light
, 1, ButtonBorderStyle
.Solid
);
145 bounds
.Inflate(-1,-1);
146 ControlPaint
.DrawBorder(paintOn
, bounds
, light
, 1, ButtonBorderStyle
.Solid
,
147 light
, 1, ButtonBorderStyle
.Solid
, dark
, 1, ButtonBorderStyle
.Solid
,
148 dark
, 1, ButtonBorderStyle
.Solid
);
150 SizeF sz
= paintOn
.MeasureString( Text
, Font
);
152 paintOn
.FillRectangle( br
, new RectangleF(new PointF((float)bounds
.Left
+ 3.0F
, 0.0F
), sz
));
155 //paintOn.DrawString(Text, Font, SystemBrushes.ControlText, (float)bounds.Left + 5, 0);
156 e
.Graphics
.DrawImage(bmp
, 0, 0, bmp
.Width
, bmp
.Height
);
160 catch/*(Exception ex)*/ {
166 protected override bool ProcessMnemonic(char charCode
) {
168 return base.ProcessMnemonic(charCode
);
172 protected override void WndProc(ref Message m
) {
173 switch ((Msg
) m
.Msg
) {
174 case Msg
.WM_ERASEBKGND
:
175 m
.Result
= (IntPtr
)1;
178 base.WndProc (ref m
);