2007-01-02 Mike Kestner <mkestner@novell.com>
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / UserControl.cs
1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
8 // 
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
11 // 
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 //
20 // Copyright (c) 2004-2005 Novell, Inc.
21 //
22 // Authors:
23 //      Peter Bartok    pbartok@novell.com
24 //
25
26 using System;
27 using System.ComponentModel;
28 using System.ComponentModel.Design;
29 using System.Drawing;
30 using System.Runtime.InteropServices;
31
32 namespace System.Windows.Forms {
33         [DefaultEvent("Load")]
34         [DesignerCategory("UserControl")]
35         [Designer("System.Windows.Forms.Design.ControlDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
36         [Designer("System.Windows.Forms.Design.UserControlDocumentDesigner, " + Consts.AssemblySystem_Design, typeof(IRootDesigner))]
37 #if NET_2_0
38         [ClassInterface (ClassInterfaceType.AutoDispatch)]
39         [ComVisible (true)]
40 #endif
41         public class UserControl : ContainerControl {
42                 #region Public Constructors
43                 public UserControl() {
44 #if NET_2_0
45                         SetStyle (ControlStyles.SupportsTransparentBackColor, true);
46 #endif
47                 }
48                 #endregion      // Public Constructors
49
50                 #region Public Instance Properties
51                 protected override Size DefaultSize {
52                         get {
53                                 return new Size(150, 150);
54                         }
55                 }
56
57
58                 [Bindable(false)]
59                 [Browsable(false)]
60                 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
61                 [EditorBrowsable(EditorBrowsableState.Never)]
62                 public override string Text {
63                         get {
64                                 return base.Text;
65                         }
66
67                         set {
68                                 base.Text = value;
69                         }
70                 }
71                 #endregion      // Public Instance Properties
72
73                 #region Protected Instance Methods
74                 [EditorBrowsable(EditorBrowsableState.Advanced)]
75                 protected override void OnCreateControl() {
76                         base.OnCreateControl();
77
78                         // The OnCreateControl isn't neccessarily raised *before* it
79                         // becomes first visible, but that's the best we've got
80                         OnLoad(EventArgs.Empty);
81                 }
82
83                 [EditorBrowsable(EditorBrowsableState.Advanced)]
84                 protected virtual void OnLoad(EventArgs e) {
85                         EventHandler eh = (EventHandler)(Events [LoadEvent]);
86                         if (eh != null)
87                                 eh (this, e);
88                 }
89
90                 [EditorBrowsable(EditorBrowsableState.Advanced)]
91                 protected override void OnMouseDown(MouseEventArgs e) {
92                         base.OnMouseDown(e);
93                 }
94
95                 [EditorBrowsable(EditorBrowsableState.Advanced)]
96                 protected override void WndProc(ref Message m) {
97                         base.WndProc(ref m);
98                 }
99                 #endregion      // Protected Instance Methods
100
101                 #region Events
102                 static object LoadEvent = new object ();
103
104                 public event EventHandler Load {
105                         add { Events.AddHandler (LoadEvent, value); }
106                         remove { Events.RemoveHandler (LoadEvent, value); }
107                 }
108
109                 [Browsable(false)]
110                 [EditorBrowsable(EditorBrowsableState.Never)]
111                 public new event EventHandler TextChanged {
112                         add { base.TextChanged += value; }
113                         remove { base.TextChanged -= value; }
114                 }
115
116                 #endregion      // Events
117
118 #if NET_2_0
119                 protected override void OnResize (EventArgs e)
120                 {
121                         base.OnResize (e);
122                 }
123
124                 [Browsable (true)]
125                 [DefaultValue (BorderStyle.None)]
126                 [EditorBrowsable (EditorBrowsableState.Always)]
127                 public BorderStyle BorderStyle {
128                         get { return InternalBorderStyle; }
129                         set { InternalBorderStyle = value; }
130                 }
131 #endif
132         }
133 }