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:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
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.
20 // Copyright (c) 2004-2006 Novell, Inc.
23 // Peter Bartok pbartok@novell.com
25 // Partially based on work by:
26 // Aleksey Ryabchuk ryabchuk@yahoo.com
27 // Alexandre Pigolkine pigolkine@gmx.de
28 // Dennis Hayes dennish@raytek.com
29 // Jaak Simm jaaksimm@firm.ee
30 // John Sohn jsohn@columbus.rr.com
38 using System.ComponentModel;
39 using System.ComponentModel.Design;
40 using System.ComponentModel.Design.Serialization;
41 using System.Collections;
42 using System.Diagnostics;
44 using System.Drawing.Drawing2D;
45 using System.Reflection;
46 using System.Runtime.InteropServices;
47 using System.Security;
48 using System.Threading;
50 namespace System.Windows.Forms
54 [ClassInterface (ClassInterfaceType.AutoDispatch)]
56 [Designer("System.Windows.Forms.Design.ControlDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
57 [DefaultProperty("Text")]
58 [DefaultEvent("Click")]
59 [DesignerSerializer("System.Windows.Forms.Design.ControlCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
60 [ToolboxItemFilter("System.Windows.Forms")]
61 public class Control : Component, ISynchronizeInvoke, IWin32Window
63 , IBindableComponent, IDropTarget, IBounds
66 #region Local Variables
69 internal Rectangle bounds; // bounding rectangle for control (client area + decorations)
70 Rectangle explicit_bounds; // explicitly set bounds
71 internal object creator_thread; // thread that created the control
72 internal ControlNativeWindow window; // object for native window handle
73 private IWindowTarget window_target;
74 string name; // for object naming
77 bool is_created; // true if OnCreateControl has been sent
78 internal bool has_focus; // true if control has focus
79 internal bool is_visible; // true if control is visible
80 internal bool is_entered; // is the mouse inside the control?
81 internal bool is_enabled; // true if control is enabled (usable/not grayed out)
82 bool is_accessible; // true if the control is visible to accessibility applications
83 bool is_captured; // tracks if the control has captured the mouse
84 internal bool is_toplevel; // tracks if the control is a toplevel window
85 bool is_recreating; // tracks if the handle for the control is being recreated
86 bool causes_validation; // tracks if validation is executed on changes
87 bool is_focusing; // tracks if Focus has been called on the control and has not yet finished
88 int tab_index; // position in tab order of siblings
89 bool tab_stop; // is the control a tab stop?
90 bool is_disposed; // has the window already been disposed?
91 bool is_disposing; // is the window getting disposed?
92 Size client_size; // size of the client area (window excluding decorations)
93 Rectangle client_rect; // rectangle with the client area (window excluding decorations)
94 ControlStyles control_style; // rather win32-specific, style bits for control
96 object control_tag; // object that contains data about our control
97 internal int mouse_clicks; // Counter for mouse clicks
98 Cursor cursor; // Cursor for the window
99 internal bool allow_drop; // true if the control accepts droping objects on it
100 Region clip_region; // User-specified clip region for the window
103 internal Color foreground_color; // foreground color for control
104 internal Color background_color; // background color for control
105 Image background_image; // background image for control
106 internal Font font; // font for control
107 string text; // window/title text for control
108 internal BorderStyle border_style; // Border style of control
109 bool show_keyboard_cues; // Current keyboard cues
110 internal bool show_focus_cues; // Current focus cues
113 internal enum LayoutType {
117 Layout.LayoutEngine layout_engine;
118 internal int layout_suspended;
119 bool layout_pending; // true if our parent needs to re-layout us
120 internal AnchorStyles anchor_style; // anchoring requirements for our control
121 internal DockStyle dock_style; // docking requirements for our control
122 LayoutType layout_type;
123 private bool recalculate_distances = true; // Delay anchor calculations
125 // Please leave the next 2 as internal until DefaultLayout (2.0) is rewritten
126 internal int dist_right; // distance to the right border of the parent
127 internal int dist_bottom; // distance to the bottom border of the parent
129 // to be categorized...
130 ControlCollection child_controls; // our children
131 Control parent; // our parent control
132 AccessibleObject accessibility_object; // object that contains accessibility information about our control
133 BindingContext binding_context;
134 RightToLeft right_to_left; // drawing direction for control
135 ContextMenu context_menu; // Context menu associated with the control
136 internal bool use_compatible_text_rendering;
137 private bool use_wait_cursor;
140 DoubleBuffer backbuffer;
142 ControlBindingsCollection data_bindings;
145 static bool verify_thread_handle;
147 ImageLayout backgroundimage_layout;
151 private ContextMenuStrip context_menu_strip;
152 private bool nested_layout = false;
153 Point auto_scroll_offset;
154 private AutoSizeMode auto_size_mode;
155 private bool suppressing_key_press;
158 #endregion // Local Variables
160 #region Private Classes
161 // This helper class allows us to dispatch messages to Control.WndProc
162 internal class ControlNativeWindow : NativeWindow {
163 private Control owner;
165 public ControlNativeWindow(Control control) : base() {
170 public Control Owner {
176 protected override void OnHandleChange()
178 this.owner.WindowTarget.OnHandleChange(this.owner.Handle);
181 static internal Control ControlFromHandle(IntPtr hWnd) {
182 ControlNativeWindow window;
184 window = (ControlNativeWindow)NativeWindow.FromHandle (hWnd);
185 if (window != null) {
192 static internal Control ControlFromChildHandle (IntPtr handle) {
193 ControlNativeWindow window;
195 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
196 while (hwnd != null) {
197 window = (ControlNativeWindow)NativeWindow.FromHandle (handle);
198 if (window != null) {
207 protected override void WndProc(ref Message m) {
208 owner.WindowTarget.OnMessage(ref m);
212 private class ControlWindowTarget : IWindowTarget
214 private Control control;
216 public ControlWindowTarget(Control control)
218 this.control = control;
221 public void OnHandleChange(IntPtr newHandle)
225 public void OnMessage(ref Message m)
227 control.WndProc(ref m);
232 #region Public Classes
234 public class ControlAccessibleObject : AccessibleObject {
237 #region ControlAccessibleObject Constructors
238 public ControlAccessibleObject(Control ownerControl)
239 : base (ownerControl)
241 if (ownerControl == null)
242 throw new ArgumentNullException ("owner");
244 handle = ownerControl.Handle;
246 #endregion // ControlAccessibleObject Constructors
248 #region ControlAccessibleObject Public Instance Properties
249 public override string DefaultAction {
251 return base.DefaultAction;
255 public override string Description {
257 return base.Description;
261 public IntPtr Handle {
267 // We don't want to let them set it
271 public override string Help {
277 public override string KeyboardShortcut {
279 return base.KeyboardShortcut;
283 public override string Name {
293 public Control Owner {
299 public override AccessibleObject Parent {
306 public override AccessibleRole Role {
311 #endregion // ControlAccessibleObject Public Instance Properties
313 #region ControlAccessibleObject Public Instance Methods
314 public override int GetHelpTopic (out string fileName)
316 return base.GetHelpTopic (out fileName);
319 [MonoTODO ("Implement this")]
320 public void NotifyClients(AccessibleEvents accEvent) {
321 throw new NotImplementedException();
324 [MonoTODO ("Implement this")]
325 public void NotifyClients(AccessibleEvents accEvent, int childID) {
329 [MonoTODO ("Implement this")]
330 public void NotifyClients (AccessibleEvents accEvent, int objectID, int childID)
335 public override string ToString() {
336 return "ControlAccessibleObject: Owner = " + owner.ToString() + ", Text: " + owner.text;
339 #endregion // ControlAccessibleObject Public Instance Methods
342 private class DoubleBuffer : IDisposable
344 public Region InvalidRegion;
345 private Stack real_graphics;
346 private object back_buffer;
347 private Control parent;
348 private bool pending_disposal;
350 public DoubleBuffer (Control parent) {
351 this.parent = parent;
352 real_graphics = new Stack ();
353 int width = parent.Width;
354 int height = parent.Height;
356 if (width < 1) width = 1;
357 if (height < 1) height = 1;
359 XplatUI.CreateOffscreenDrawable (parent.Handle, width, height, out back_buffer);
363 public void Blit (PaintEventArgs pe) {
364 Graphics buffered_graphics;
365 buffered_graphics = XplatUI.GetOffscreenGraphics (back_buffer);
366 XplatUI.BlitFromOffscreen (parent.Handle, pe.Graphics, back_buffer, buffered_graphics, pe.ClipRectangle);
367 buffered_graphics.Dispose ();
370 public void Start (PaintEventArgs pe) {
371 // We need to get the graphics for every paint.
372 real_graphics.Push(pe.SetGraphics (XplatUI.GetOffscreenGraphics (back_buffer)));
375 public void End (PaintEventArgs pe) {
376 Graphics buffered_graphics;
377 buffered_graphics = pe.SetGraphics ((Graphics) real_graphics.Pop ());
379 if (pending_disposal)
382 XplatUI.BlitFromOffscreen (parent.Handle, pe.Graphics, back_buffer, buffered_graphics, pe.ClipRectangle);
383 InvalidRegion.Exclude (pe.ClipRectangle);
385 buffered_graphics.Dispose ();
388 public void Invalidate () {
389 if (InvalidRegion != null)
390 InvalidRegion.Dispose ();
391 InvalidRegion = new Region (parent.ClientRectangle);
394 public void Dispose () {
395 if (real_graphics.Count > 0) {
396 pending_disposal = true;
400 XplatUI.DestroyOffscreenDrawable (back_buffer);
402 if (InvalidRegion != null)
403 InvalidRegion.Dispose ();
404 InvalidRegion = null;
406 GC.SuppressFinalize (this);
409 #region IDisposable Members
410 void IDisposable.Dispose () {
420 [ListBindable (false)]
423 public class ControlCollection : Layout.ArrangedElementCollection, IList, ICollection, ICloneable, IEnumerable {
425 [DesignerSerializer("System.Windows.Forms.Design.ControlCollectionCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
426 public class ControlCollection : IList, ICollection, ICloneable, IEnumerable {
428 #region ControlCollection Local Variables
433 Control [] all_controls;
435 #endregion // ControlCollection Local Variables
437 #region ControlCollection Public Constructor
438 public ControlCollection (Control owner)
442 this.list = new ArrayList();
447 #region ControlCollection Public Instance Properties
451 get { return list.Count; }
454 public bool IsReadOnly {
456 return list.IsReadOnly;
462 public Control Owner {
463 get { return this.owner; }
466 public virtual Control this[string key] {
468 int index = IndexOfKey (key);
479 public virtual Control this[int index] {
481 if (index < 0 || index >= list.Count) {
482 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
484 return (Control)list[index];
490 #endregion // ControlCollection Public Instance Properties
492 #region ControlCollection Instance Methods
494 public virtual void Add (Control value)
499 Form form_value = value as Form;
500 Form form_owner = owner as Form;
501 bool owner_permits_toplevels = (owner is MdiClient) || (form_owner != null && form_owner.IsMdiContainer);
502 bool child_is_toplevel = value.GetTopLevel();
503 bool child_is_mdichild = form_value != null && form_value.IsMdiChild;
505 if (child_is_toplevel && !(owner_permits_toplevels && child_is_mdichild))
506 throw new ArgumentException("Cannot add a top level control to a control.", "value");
508 if (child_is_mdichild && form_value.MdiParent != null && form_value.MdiParent != owner && form_value.MdiParent != owner.Parent) {
509 throw new ArgumentException ("Form cannot be added to the Controls collection that has a valid MDI parent.", "value");
512 value.recalculate_distances = true;
514 if (Contains (value)) {
515 owner.PerformLayout();
519 if (value.tab_index == -1) {
525 end = owner.child_controls.Count;
526 for (int i = 0; i < end; i++) {
527 index = owner.child_controls[i].tab_index;
532 value.tab_index = use;
535 if (value.parent != null) {
536 value.parent.Controls.Remove(value);
542 value.ChangeParent(owner);
547 owner.UpdateChildrenZOrder();
548 owner.PerformLayout(value, "Parent");
549 owner.OnControlAdded(new ControlEventArgs(value));
552 internal void AddToList (Control c)
558 internal virtual void AddImplicit (Control control)
560 if (impl_list == null)
561 impl_list = new ArrayList ();
563 if (AllContains (control)) {
564 owner.PerformLayout ();
568 if (control.parent != null) {
569 control.parent.Controls.Remove(control);
573 impl_list.Add (control);
575 control.ChangeParent (owner);
576 control.InitLayout ();
578 owner.UpdateChildrenZOrder ();
580 // If we are adding a new control that isn't
581 // visible, don't trigger a layout
582 if (control.VisibleInternal)
583 owner.PerformLayout (control, "Parent");
586 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
588 public virtual void AddRange (Control[] controls)
590 if (controls == null)
591 throw new ArgumentNullException ("controls");
593 owner.SuspendLayout ();
596 for (int i = 0; i < controls.Length; i++)
599 owner.ResumeLayout ();
603 internal virtual void AddRangeImplicit (Control [] controls)
605 if (controls == null)
606 throw new ArgumentNullException ("controls");
608 owner.SuspendLayout ();
611 for (int i = 0; i < controls.Length; i++)
612 AddImplicit (controls [i]);
614 owner.ResumeLayout (false);
621 public virtual void Clear ()
625 // MS sends remove events in reverse order
626 while (list.Count > 0) {
627 Remove((Control)list[list.Count - 1]);
631 internal virtual void ClearImplicit ()
633 if (impl_list == null)
639 public bool Contains (Control control)
641 return list.Contains (control);
644 internal bool ImplicitContains (Control value) {
645 if (impl_list == null)
648 return impl_list.Contains (value);
651 internal bool AllContains (Control value) {
652 return Contains (value) || ImplicitContains (value);
656 public virtual bool ContainsKey (string key)
658 return IndexOfKey (key) >= 0;
663 public void CopyTo (Array dest, int index)
665 list.CopyTo (dest, index);
668 public override bool Equals (object other)
670 if (other is ControlCollection && (((ControlCollection)other).owner==this.owner)) {
679 // LAMESPEC: MSDN says AE, MS implementation throws ANE
680 public Control[] Find (string key, bool searchAllChildren)
682 if (string.IsNullOrEmpty (key))
683 throw new ArgumentNullException ("key");
685 ArrayList al = new ArrayList ();
687 foreach (Control c in list) {
688 if (c.Name.Equals (key, StringComparison.CurrentCultureIgnoreCase))
691 if (searchAllChildren)
692 al.AddRange (c.Controls.Find (key, true));
695 return (Control[])al.ToArray (typeof (Control));
699 public int GetChildIndex(Control child) {
700 return GetChildIndex(child, false);
708 GetChildIndex(Control child, bool throwException) {
711 index=list.IndexOf(child);
713 if (index==-1 && throwException) {
714 throw new ArgumentException("Not a child control", "child");
720 public override IEnumerator
725 return new ControlCollectionEnumerator (list);
728 internal IEnumerator GetAllEnumerator () {
729 Control [] res = GetAllControls ();
730 return res.GetEnumerator ();
733 internal ArrayList ImplicitControls {
734 get { return impl_list; }
737 internal Control [] GetAllControls () {
738 if (all_controls != null)
741 if (impl_list == null) {
742 all_controls = (Control []) list.ToArray (typeof (Control));
746 all_controls = new Control [list.Count + impl_list.Count];
747 impl_list.CopyTo (all_controls);
748 list.CopyTo (all_controls, impl_list.Count);
754 public override int GetHashCode ()
756 return base.GetHashCode ();
760 public int IndexOf (Control control)
762 return list.IndexOf (control);
766 public virtual int IndexOfKey (string key)
768 if (string.IsNullOrEmpty (key))
771 for (int i = 0; i < list.Count; i++)
772 if (((Control)list[i]).Name.Equals (key, StringComparison.CurrentCultureIgnoreCase))
779 public virtual void Remove (Control value)
787 owner.PerformLayout(value, "Parent");
788 owner.OnControlRemoved(new ControlEventArgs(value));
790 ContainerControl container = owner.InternalGetContainerControl ();
791 if (container != null) {
792 // Inform any container controls about the loss of a child control
793 // so that they can update their active control
794 container.ChildControlRemoved (value);
797 value.ChangeParent(null);
799 owner.UpdateChildrenZOrder();
802 internal virtual void RemoveImplicit (Control control)
804 if (impl_list != null) {
806 impl_list.Remove (control);
807 owner.PerformLayout (control, "Parent");
808 owner.OnControlRemoved (new ControlEventArgs (control));
810 control.ChangeParent (null);
811 owner.UpdateChildrenZOrder ();
817 public void RemoveAt (int index)
819 if (index < 0 || index >= list.Count)
820 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
822 Remove ((Control) list [index]);
826 public virtual void RemoveByKey (string key)
828 int index = IndexOfKey (key);
840 SetChildIndex(Control child, int newIndex)
843 throw new ArgumentNullException ("child");
847 old_index=list.IndexOf(child);
849 throw new ArgumentException("Not a child control", "child");
852 if (old_index==newIndex) {
857 list.RemoveAt(old_index);
859 if (newIndex>list.Count) {
862 list.Insert(newIndex, child);
864 child.UpdateZOrder();
865 owner.PerformLayout();
868 #endregion // ControlCollection Private Instance Methods
870 #region ControlCollection Interface Properties
873 object IList.this [int index] {
875 if (index<0 || index>=list.Count) {
876 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
882 if (!(value is Control)) {
883 throw new ArgumentException("Object of type Control required", "value");
887 Control ctrl = (Control) value;
890 ctrl.ChangeParent(owner);
894 owner.UpdateChildrenZOrder();
895 owner.PerformLayout(ctrl, "Parent");
899 bool IList.IsFixedSize {
905 bool ICollection.IsSynchronized {
907 return list.IsSynchronized;
911 object ICollection.SyncRoot {
913 return list.SyncRoot;
918 #endregion // ControlCollection Interface Properties
920 #region ControlCollection Interface Methods
922 int IList.Add (object control)
924 if (!(control is Control))
925 throw new ArgumentException ("Object of type Control required", "control");
928 throw new ArgumentException ("control", "Cannot add null controls");
930 bool owner_permits_toplevels = (owner is MdiClient) || (owner is Form && ((Form)owner).IsMdiContainer);
931 bool child_is_toplevel = ((Control) control).GetTopLevel ();
932 bool child_is_mdichild = (control is Form && ((Form) control).IsMdiChild);
934 if (child_is_toplevel && !(owner_permits_toplevels && child_is_mdichild))
935 throw new ArgumentException ("Cannot add a top level control to a control.", "control");
937 return list.Add (control);
941 bool IList.Contains (object control)
943 if (!(control is Control))
944 throw new ArgumentException ("Object of type Control required", "control");
946 return this.Contains ((Control) control);
949 int IList.IndexOf (object control)
951 if (!(control is Control))
952 throw new ArgumentException ("Object of type Control required", "control");
954 return this.IndexOf ((Control) control);
957 void IList.Insert (int index, object value)
959 if (!(value is Control))
960 throw new ArgumentException("Object of type Control required", "value");
963 list.Insert (index, value);
967 void IList.Remove (object control)
969 if (!(control is Control))
970 throw new ArgumentException ("Object of type Control required", "control");
973 list.Remove (control);
976 Object ICloneable.Clone ()
978 ControlCollection clone = new ControlCollection (this.owner);
979 clone.list = (ArrayList)list.Clone (); // FIXME: Do we need this?
983 #endregion // ControlCollection Interface Methods
985 private class ControlCollectionEnumerator : IEnumerator
987 private ArrayList list;
990 public ControlCollectionEnumerator (ArrayList collection)
995 #region IEnumerator Members
996 public object Current {
999 return list[position];
1000 } catch (IndexOutOfRangeException) {
1001 throw new InvalidOperationException ();
1006 public bool MoveNext ()
1009 return (position < list.Count);
1012 public void Reset ()
1020 #endregion // ControlCollection Class
1022 #region Public Constructors
1026 if (WindowsFormsSynchronizationContext.AutoInstall)
1027 if (!(SynchronizationContext.Current is WindowsFormsSynchronizationContext))
1028 SynchronizationContext.SetSynchronizationContext (new WindowsFormsSynchronizationContext ());
1031 layout_type = LayoutType.Anchor;
1032 anchor_style = AnchorStyles.Top | AnchorStyles.Left;
1036 is_captured = false;
1037 is_disposed = false;
1040 layout_pending = false;
1041 is_toplevel = false;
1042 causes_validation = true;
1044 layout_suspended = 0;
1048 right_to_left = RightToLeft.Inherit;
1049 border_style = BorderStyle.None;
1050 background_color = Color.Empty;
1054 ime_mode = ImeMode.Inherit;
1055 use_compatible_text_rendering = true;
1056 show_keyboard_cues = false;
1057 show_focus_cues = SystemInformation.MenuAccessKeysUnderlined;
1060 backgroundimage_layout = ImageLayout.Tile;
1061 use_compatible_text_rendering = Application.use_compatible_text_rendering;
1062 padding = this.DefaultPadding;
1063 maximum_size = new Size();
1064 minimum_size = new Size();
1065 margin = this.DefaultMargin;
1066 auto_size_mode = AutoSizeMode.GrowOnly;
1069 control_style = ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint |
1070 ControlStyles.Selectable | ControlStyles.StandardClick |
1071 ControlStyles.StandardDoubleClick;
1073 control_style |= ControlStyles.UseTextForAccessibility;
1077 background_image = null;
1078 text = string.Empty;
1079 name = string.Empty;
1081 window_target = new ControlWindowTarget(this);
1082 window = new ControlNativeWindow(this);
1083 child_controls = CreateControlsInstance();
1085 bounds.Size = DefaultSize;
1086 client_size = ClientSizeFromSize (bounds.Size);
1087 client_rect = new Rectangle (Point.Empty, client_size);
1088 explicit_bounds = bounds;
1091 public Control (Control parent, string text) : this()
1097 public Control (Control parent, string text, int left, int top, int width, int height) : this()
1103 bounds.Height=height;
1104 SetBounds(left, top, width, height, BoundsSpecified.All);
1108 public Control (string text) : this()
1113 public Control (string text, int left, int top, int width, int height) : this()
1118 bounds.Height=height;
1119 SetBounds(left, top, width, height, BoundsSpecified.All);
1123 private delegate void RemoveDelegate(object c);
1125 protected override void Dispose (bool disposing)
1127 if (!is_disposed && disposing) {
1128 is_disposing = true;
1131 DisposeBackBuffer ();
1133 if (this.InvokeRequired) {
1134 if (Application.MessageLoop && IsHandleCreated) {
1135 this.BeginInvokeInternal(new MethodInvoker(DestroyHandle), null);
1142 parent.Controls.Remove(this);
1144 Control [] children = child_controls.GetAllControls ();
1145 for (int i=0; i<children.Length; i++) {
1146 children[i].parent = null; // Need to set to null or our child will try and remove from ourselves and crash
1147 children[i].Dispose();
1151 base.Dispose(disposing);
1153 #endregion // Public Constructors
1155 #region Internal Properties
1157 private MenuTracker active_tracker;
1159 internal MenuTracker ActiveTracker {
1160 get { return active_tracker; }
1162 if (value == active_tracker)
1165 Capture = value != null;
1166 active_tracker = value;
1170 // Control is currently selected, like Focused, except maintains state
1171 // when Form loses focus
1172 internal bool InternalSelected {
1174 IContainerControl container;
1176 container = GetContainerControl();
1178 if (container != null && container.ActiveControl == this)
1185 // Looks for focus in child controls
1186 // and also in the implicit ones
1187 internal bool InternalContainsFocus {
1189 IntPtr focused_window;
1191 focused_window = XplatUI.GetFocus();
1192 if (IsHandleCreated) {
1193 if (focused_window == Handle)
1196 foreach (Control child_control in child_controls.GetAllControls ())
1197 if (child_control.InternalContainsFocus)
1205 // Mouse is currently within the control's bounds
1206 internal bool Entered {
1207 get { return this.is_entered; }
1210 internal bool VisibleInternal {
1211 get { return is_visible; }
1214 internal LayoutType ControlLayoutType {
1215 get { return layout_type; }
1218 internal BorderStyle InternalBorderStyle {
1220 return border_style;
1224 if (!Enum.IsDefined (typeof (BorderStyle), value))
1225 throw new InvalidEnumArgumentException (string.Format("Enum argument value '{0}' is not valid for BorderStyle", value));
1227 if (border_style != value) {
1228 border_style = value;
1230 if (IsHandleCreated) {
1231 XplatUI.SetBorderStyle (window.Handle, (FormBorderStyle)border_style);
1235 client_size = ClientSizeFromSize (bounds.Size);
1240 internal Size InternalClientSize { set { this.client_size = value; } }
1241 internal virtual bool ActivateOnShow { get { return true; } }
1242 internal Rectangle ExplicitBounds { get { return this.explicit_bounds; } set { this.explicit_bounds = value; } }
1244 internal bool ValidationFailed {
1246 ContainerControl c = InternalGetContainerControl ();
1248 return c.validation_failed;
1252 ContainerControl c = InternalGetContainerControl ();
1254 c.validation_failed = value;
1257 #endregion // Internal Properties
1259 #region Private & Internal Methods
1262 void IDropTarget.OnDragDrop (DragEventArgs drgEvent)
1264 OnDragDrop (drgEvent);
1267 void IDropTarget.OnDragEnter (DragEventArgs drgEvent)
1269 OnDragEnter (drgEvent);
1272 void IDropTarget.OnDragLeave (EventArgs e)
1277 void IDropTarget.OnDragOver (DragEventArgs drgEvent)
1279 OnDragOver (drgEvent);
1283 internal IAsyncResult BeginInvokeInternal (Delegate method, object [] args) {
1284 return BeginInvokeInternal (method, args, FindControlToInvokeOn ());
1287 internal IAsyncResult BeginInvokeInternal (Delegate method, object [] args, Control control) {
1288 AsyncMethodResult result;
1289 AsyncMethodData data;
1291 result = new AsyncMethodResult ();
1292 data = new AsyncMethodData ();
1294 data.Handle = control.GetInvokableHandle ();
1295 data.Method = method;
1297 data.Result = result;
1300 if (!ExecutionContext.IsFlowSuppressed ()) {
1301 data.Context = ExecutionContext.Capture ();
1304 #if !MWF_ON_MSRUNTIME
1305 if (SecurityManager.SecurityEnabled) {
1306 data.Stack = CompressedStack.GetCompressedStack ();
1311 XplatUI.SendAsyncMethod (data);
1315 // The CheckForIllegalCrossThreadCalls in the #if 2.0 of
1316 // Control.Handle throws an exception when we are trying
1317 // to get the Handle to properly invoke on. This avoids that.
1318 private IntPtr GetInvokableHandle ()
1320 if (!IsHandleCreated)
1323 return window.Handle;
1326 internal void PointToClient (ref int x, ref int y) {
1327 XplatUI.ScreenToClient (Handle, ref x, ref y);
1330 internal void PointToScreen (ref int x, ref int y) {
1331 XplatUI.ClientToScreen (Handle, ref x, ref y);
1334 internal bool IsRecreating {
1336 return is_recreating;
1340 internal Graphics DeviceContext {
1341 get { return Hwnd.GraphicsContext; }
1344 // An internal way to have a fixed height
1345 // Basically for DataTimePicker 2.0
1346 internal virtual int OverrideHeight (int height)
1351 private void ProcessActiveTracker (ref Message m)
1353 bool is_up = ((Msg) m.Msg == Msg.WM_LBUTTONUP) ||
1354 ((Msg) m.Msg == Msg.WM_RBUTTONUP);
1356 MouseButtons mb = FromParamToMouseButtons ((int) m.WParam.ToInt32 ());
1358 // We add in the button that was released (not sent in WParam)
1360 switch ((Msg)m.Msg) {
1361 case Msg.WM_LBUTTONUP:
1362 mb |= MouseButtons.Left;
1364 case Msg.WM_RBUTTONUP:
1365 mb |= MouseButtons.Right;
1370 MouseEventArgs args = new MouseEventArgs (
1373 Control.MousePosition.X,
1374 Control.MousePosition.Y,
1378 active_tracker.OnMouseUp (args);
1381 if (!active_tracker.OnMouseDown (args)) {
1382 Control control = GetRealChildAtPoint (Cursor.Position);
1383 if (control != null) {
1384 Point pt = control.PointToClient (Cursor.Position);
1385 XplatUI.SendMessage (control.Handle,
1388 MakeParam (pt.X, pt.Y));
1394 private Control FindControlToInvokeOn ()
1398 if (p.IsHandleCreated)
1401 } while (p != null);
1403 if (p == null || !p.IsHandleCreated)
1404 throw new InvalidOperationException ("Cannot call Invoke or BeginInvoke on a control until the window handle is created");
1409 private void InvalidateBackBuffer () {
1410 if (backbuffer != null)
1411 backbuffer.Invalidate ();
1414 private DoubleBuffer GetBackBuffer () {
1415 if (backbuffer == null)
1416 backbuffer = new DoubleBuffer (this);
1420 private void DisposeBackBuffer () {
1421 if (backbuffer != null) {
1422 backbuffer.Dispose ();
1427 internal static void SetChildColor(Control parent) {
1430 for (int i=0; i < parent.child_controls.Count; i++) {
1431 child=parent.child_controls[i];
1432 if (child.child_controls.Count>0) {
1433 SetChildColor(child);
1438 internal bool Select(Control control) {
1439 IContainerControl container;
1441 if (control == null) {
1445 container = GetContainerControl();
1446 if (container != null && (Control)container != control) {
1447 container.ActiveControl = control;
1449 else if (control.IsHandleCreated) {
1450 XplatUI.SetFocus(control.window.Handle);
1455 internal virtual void DoDefaultAction() {
1456 // Only here to be overriden by our actual controls; this is needed by the accessibility class
1459 internal static IntPtr MakeParam (int low, int high){
1460 return new IntPtr (high << 16 | low & 0xffff);
1463 internal static int LowOrder (int param) {
1464 return ((int)(short)(param & 0xffff));
1467 internal static int HighOrder (long param) {
1468 return ((int)(short)(param >> 16));
1471 // This method exists so controls overriding OnPaintBackground can have default background painting done
1472 internal virtual void PaintControlBackground (PaintEventArgs pevent) {
1474 bool tbstyle_flat = ((CreateParams.Style & (int) ToolBarStyles.TBSTYLE_FLAT) != 0);
1476 // If we have transparent background
1477 if (((BackColor.A != 0xff) && GetStyle(ControlStyles.SupportsTransparentBackColor)) || tbstyle_flat) {
1478 if (parent != null) {
1479 PaintEventArgs parent_pe;
1480 GraphicsState state;
1482 parent_pe = new PaintEventArgs(pevent.Graphics, new Rectangle(pevent.ClipRectangle.X + Left, pevent.ClipRectangle.Y + Top, pevent.ClipRectangle.Width, pevent.ClipRectangle.Height));
1484 state = parent_pe.Graphics.Save();
1485 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1486 parent.OnPaintBackground(parent_pe);
1487 parent_pe.Graphics.Restore(state);
1489 state = parent_pe.Graphics.Save();
1490 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1491 parent.OnPaint(parent_pe);
1492 parent_pe.Graphics.Restore(state);
1493 parent_pe.SetGraphics(null);
1497 if ((clip_region != null) && (XplatUI.UserClipWontExposeParent)) {
1498 if (parent != null) {
1499 PaintEventArgs parent_pe;
1501 GraphicsState state;
1504 hwnd = Hwnd.ObjectFromHandle(Handle);
1507 parent_pe = new PaintEventArgs(pevent.Graphics, new Rectangle(pevent.ClipRectangle.X + Left, pevent.ClipRectangle.Y + Top, pevent.ClipRectangle.Width, pevent.ClipRectangle.Height));
1509 region = new Region ();
1511 region.Union(ClientRectangle);
1513 foreach (Rectangle r in hwnd.ClipRectangles) {
1517 state = parent_pe.Graphics.Save();
1518 parent_pe.Graphics.Clip = region;
1520 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1521 parent.OnPaintBackground(parent_pe);
1522 parent_pe.Graphics.Restore(state);
1524 state = parent_pe.Graphics.Save();
1525 parent_pe.Graphics.Clip = region;
1527 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1528 parent.OnPaint(parent_pe);
1529 parent_pe.Graphics.Restore(state);
1530 parent_pe.SetGraphics(null);
1532 region.Intersect(clip_region);
1533 pevent.Graphics.Clip = region;
1538 if (background_image == null) {
1539 if (!tbstyle_flat) {
1540 Rectangle paintRect = new Rectangle(pevent.ClipRectangle.X, pevent.ClipRectangle.Y, pevent.ClipRectangle.Width, pevent.ClipRectangle.Height);
1541 Brush pen = ThemeEngine.Current.ResPool.GetSolidBrush(BackColor);
1542 pevent.Graphics.FillRectangle(pen, paintRect);
1547 DrawBackgroundImage (pevent.Graphics);
1550 void DrawBackgroundImage (Graphics g) {
1552 Rectangle drawing_rectangle = new Rectangle ();
1553 g.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (BackColor), ClientRectangle);
1555 switch (backgroundimage_layout)
1557 case ImageLayout.Tile:
1558 using (TextureBrush b = new TextureBrush (background_image, WrapMode.Tile)) {
1559 g.FillRectangle (b, ClientRectangle);
1562 case ImageLayout.Center:
1563 drawing_rectangle.Location = new Point (ClientSize.Width / 2 - background_image.Width / 2, ClientSize.Height / 2 - background_image.Height / 2);
1564 drawing_rectangle.Size = background_image.Size;
1566 case ImageLayout.None:
1567 drawing_rectangle.Location = Point.Empty;
1568 drawing_rectangle.Size = background_image.Size;
1570 case ImageLayout.Stretch:
1571 drawing_rectangle = ClientRectangle;
1573 case ImageLayout.Zoom:
1574 drawing_rectangle = ClientRectangle;
1575 if ((float)background_image.Width / (float)background_image.Height < (float)drawing_rectangle.Width / (float) drawing_rectangle.Height) {
1576 drawing_rectangle.Width = (int) (background_image.Width * ((float)drawing_rectangle.Height / (float)background_image.Height));
1577 drawing_rectangle.X = (ClientRectangle.Width - drawing_rectangle.Width) / 2;
1579 drawing_rectangle.Height = (int) (background_image.Height * ((float)drawing_rectangle.Width / (float)background_image.Width));
1580 drawing_rectangle.Y = (ClientRectangle.Height - drawing_rectangle.Height) / 2;
1587 g.DrawImage (background_image, drawing_rectangle);
1590 using (TextureBrush b = new TextureBrush (background_image, WrapMode.Tile)) {
1591 g.FillRectangle (b, ClientRectangle);
1596 internal virtual void DndEnter (DragEventArgs e) {
1602 internal virtual void DndOver (DragEventArgs e) {
1608 internal virtual void DndDrop (DragEventArgs e) {
1611 } catch (Exception exc) {
1612 Console.Error.WriteLine ("MWF: Exception while dropping:");
1613 Console.Error.WriteLine (exc);
1617 internal virtual void DndLeave (EventArgs e) {
1623 internal virtual void DndFeedback(GiveFeedbackEventArgs e) {
1629 internal virtual void DndContinueDrag(QueryContinueDragEventArgs e) {
1631 OnQueryContinueDrag(e);
1635 internal static MouseButtons FromParamToMouseButtons (long param) {
1636 MouseButtons buttons = MouseButtons.None;
1638 if ((param & (long) MsgButtons.MK_LBUTTON) != 0)
1639 buttons |= MouseButtons.Left;
1641 if ((param & (long)MsgButtons.MK_MBUTTON) != 0)
1642 buttons |= MouseButtons.Middle;
1644 if ((param & (long)MsgButtons.MK_RBUTTON) != 0)
1645 buttons |= MouseButtons.Right;
1650 internal virtual void FireEnter () {
1651 OnEnter (EventArgs.Empty);
1654 internal virtual void FireLeave () {
1655 OnLeave (EventArgs.Empty);
1658 internal virtual void FireValidating (CancelEventArgs ce) {
1662 internal virtual void FireValidated () {
1663 OnValidated (EventArgs.Empty);
1666 internal virtual bool ProcessControlMnemonic(char charCode) {
1667 return ProcessMnemonic(charCode);
1670 private static Control FindFlatForward(Control container, Control start) {
1677 end = container.child_controls.Count;
1680 if (start != null) {
1681 index = start.tab_index;
1686 for (int i = 0; i < end; i++) {
1687 if (start == container.child_controls[i]) {
1692 if (found == null || found.tab_index > container.child_controls[i].tab_index) {
1693 if (container.child_controls[i].tab_index > index || (hit && container.child_controls[i].tab_index == index)) {
1694 found = container.child_controls[i];
1701 private static Control FindControlForward(Control container, Control start) {
1706 if (start == null) {
1707 return FindFlatForward(container, start);
1710 if (start.child_controls != null && start.child_controls.Count > 0 &&
1711 (start == container || !((start is IContainerControl) && start.GetStyle(ControlStyles.ContainerControl)))) {
1712 return FindControlForward(start, null);
1715 while (start != container) {
1716 found = FindFlatForward(start.parent, start);
1717 if (found != null) {
1720 start = start.parent;
1726 private static Control FindFlatBackward(Control container, Control start) {
1733 end = container.child_controls.Count;
1736 if (start != null) {
1737 index = start.tab_index;
1739 index = int.MaxValue;
1742 for (int i = end - 1; i >= 0; i--) {
1743 if (start == container.child_controls[i]) {
1748 if (found == null || found.tab_index < container.child_controls[i].tab_index) {
1749 if (container.child_controls[i].tab_index < index || (hit && container.child_controls[i].tab_index == index))
1750 found = container.child_controls[i];
1757 private static Control FindControlBackward(Control container, Control start) {
1759 Control found = null;
1761 if (start == null) {
1762 found = FindFlatBackward(container, start);
1764 else if (start != container) {
1765 if (start.parent != null) {
1766 found = FindFlatBackward(start.parent, start);
1768 if (found == null) {
1769 if (start.parent != container)
1770 return start.parent;
1776 if (found == null || start.parent == null)
1779 while (found != null && (found == container || (!((found is IContainerControl) && found.GetStyle(ControlStyles.ContainerControl))) &&
1780 found.child_controls != null && found.child_controls.Count > 0)) {
1781 // while (ctl.child_controls != null && ctl.child_controls.Count > 0 &&
1782 // (ctl == this || (!((ctl is IContainerControl) && ctl.GetStyle(ControlStyles.ContainerControl))))) {
1783 found = FindFlatBackward(found, null);
1793 if (start != null) {
1794 found = FindFlatBackward(start.parent, start);
1795 if (found == null) {
1796 if (start.parent != container) {
1797 return start.parent;
1801 if (found == null) {
1802 found = FindFlatBackward(container, start);
1805 if (container != start) {
1806 while ((found != null) && (!found.Contains(start)) && found.child_controls != null && found.child_controls.Count > 0 && !(found is IContainerControl)) {// || found.GetStyle(ControlStyles.ContainerControl))) {
1807 found = FindControlBackward(found, null);
1808 if (found != null) {
1817 internal virtual void HandleClick(int clicks, MouseEventArgs me) {
1818 bool standardclick = GetStyle (ControlStyles.StandardClick);
1819 bool standardclickclick = GetStyle (ControlStyles.StandardDoubleClick);
1820 if ((clicks > 1) && standardclick && standardclickclick) {
1823 OnMouseDoubleClick (me);
1825 OnDoubleClick(EventArgs.Empty);
1827 } else if (clicks == 1 && standardclick && !ValidationFailed) {
1832 OnClick(EventArgs.Empty);
1837 internal void CaptureWithConfine (Control ConfineWindow) {
1838 if (this.IsHandleCreated && !is_captured) {
1840 XplatUI.GrabWindow (this.window.Handle, ConfineWindow.Handle);
1844 private void CheckDataBindings () {
1845 if (data_bindings == null)
1848 foreach (Binding binding in data_bindings) {
1853 private void ChangeParent(Control new_parent) {
1857 Color pre_fore_color;
1858 Color pre_back_color;
1859 RightToLeft pre_rtl;
1861 // These properties are inherited from our parent
1862 // Get them pre parent-change and then send events
1863 // if they are changed after we have our new parent
1864 pre_enabled = Enabled;
1865 pre_visible = Visible;
1867 pre_fore_color = ForeColor;
1868 pre_back_color = BackColor;
1869 pre_rtl = RightToLeft;
1870 // MS doesn't seem to send a CursorChangedEvent
1872 parent = new_parent;
1874 Form frm = this as Form;
1876 frm.ChangingParent (new_parent);
1877 } else if (IsHandleCreated) {
1878 IntPtr parent_handle = IntPtr.Zero;
1879 if (new_parent != null && new_parent.IsHandleCreated)
1880 parent_handle = new_parent.Handle;
1881 XplatUI.SetParent (Handle, parent_handle);
1884 OnParentChanged(EventArgs.Empty);
1886 if (pre_enabled != Enabled) {
1887 OnEnabledChanged(EventArgs.Empty);
1890 if (pre_visible != Visible) {
1891 OnVisibleChanged(EventArgs.Empty);
1894 if (pre_font != Font) {
1895 OnFontChanged(EventArgs.Empty);
1898 if (pre_fore_color != ForeColor) {
1899 OnForeColorChanged(EventArgs.Empty);
1902 if (pre_back_color != BackColor) {
1903 OnBackColorChanged(EventArgs.Empty);
1906 if (pre_rtl != RightToLeft) {
1907 // MS sneaks a OnCreateControl and OnHandleCreated in here, I guess
1908 // because when RTL changes they have to recreate the win32 control
1909 // We don't really need that (until someone runs into compatibility issues)
1910 OnRightToLeftChanged(EventArgs.Empty);
1913 if ((new_parent != null) && new_parent.Created && is_visible && !Created) {
1917 if ((binding_context == null) && Created) {
1918 OnBindingContextChanged(EventArgs.Empty);
1922 // Sometimes we need to do this calculation without it being virtual (constructor)
1923 internal Size InternalSizeFromClientSize (Size clientSize)
1925 Rectangle ClientRect;
1926 Rectangle WindowRect;
1929 ClientRect = new Rectangle (0, 0, clientSize.Width, clientSize.Height);
1930 cp = this.CreateParams;
1932 if (XplatUI.CalculateWindowRect (ref ClientRect, cp, null, out WindowRect))
1933 return new Size (WindowRect.Width, WindowRect.Height);
1938 internal Size ClientSizeFromSize (Size size)
1940 // Calling this gives us the difference in Size and ClientSize.
1941 // We just have to apply that difference to our given size.
1942 Size client_size = this.InternalSizeFromClientSize (size);
1944 if (client_size == Size.Empty)
1947 return new Size (size.Width - (client_size.Width - size.Width), size.Height - (client_size.Height - size.Height));
1950 internal CreateParams GetCreateParams ()
1952 return CreateParams;
1956 internal virtual Size GetPreferredSizeCore (Size proposedSize)
1958 return this.explicit_bounds.Size;
1962 private void UpdateDistances() {
1963 if (parent != null) {
1964 if (bounds.Width >= 0)
1965 dist_right = parent.ClientSize.Width - bounds.X - bounds.Width;
1966 if (bounds.Height >= 0)
1967 dist_bottom = parent.ClientSize.Height - bounds.Y - bounds.Height;
1969 recalculate_distances = false;
1973 private Cursor GetAvailableCursor ()
1975 if (Cursor != null && Enabled) {
1979 if (Parent != null) {
1980 return Parent.GetAvailableCursor ();
1983 return Cursors.Default;
1986 private void UpdateCursor ()
1988 if (!IsHandleCreated)
1992 XplatUI.SetCursor (window.Handle, GetAvailableCursor ().handle);
1996 Point pt = PointToClient (Cursor.Position);
1998 if ((!bounds.Contains (pt) && !Capture) || (GetChildAtPoint (pt) != null))
2001 if (cursor != null || use_wait_cursor) {
2002 XplatUI.SetCursor (window.Handle, Cursor.handle);
2004 XplatUI.SetCursor (window.Handle, GetAvailableCursor ().handle);
2008 private bool UseDoubleBuffering {
2010 if (!ThemeEngine.Current.DoubleBufferingSupported)
2017 return (control_style & ControlStyles.DoubleBuffer) != 0;
2020 #endregion // Private & Internal Methods
2022 #region Public Static Properties
2023 public static Color DefaultBackColor {
2025 return ThemeEngine.Current.DefaultControlBackColor;
2029 public static Font DefaultFont {
2031 return ThemeEngine.Current.DefaultFont;
2035 public static Color DefaultForeColor {
2037 return ThemeEngine.Current.DefaultControlForeColor;
2041 public static Keys ModifierKeys {
2043 return XplatUI.State.ModifierKeys;
2047 public static MouseButtons MouseButtons {
2049 return XplatUI.State.MouseButtons;
2053 public static Point MousePosition {
2055 return Cursor.Position;
2060 [EditorBrowsable (EditorBrowsableState.Advanced)]
2061 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
2064 public static bool CheckForIllegalCrossThreadCalls
2067 return verify_thread_handle;
2071 verify_thread_handle = value;
2075 #endregion // Public Static Properties
2077 #region Public Instance Properties
2078 [EditorBrowsable(EditorBrowsableState.Advanced)]
2080 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2081 public AccessibleObject AccessibilityObject {
2083 if (accessibility_object==null) {
2084 accessibility_object=CreateAccessibilityInstance();
2086 return accessibility_object;
2090 [EditorBrowsable(EditorBrowsableState.Advanced)]
2092 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2093 public string AccessibleDefaultActionDescription {
2095 if (accessibility_object != null)
2096 return accessibility_object.default_action;
2102 if (accessibility_object != null)
2103 accessibility_object.default_action = value;
2108 [DefaultValue(null)]
2109 [MWFCategory("Accessibility")]
2110 public string AccessibleDescription {
2112 if (accessibility_object != null)
2113 return accessibility_object.description;
2119 if (accessibility_object != null)
2120 accessibility_object.description = value;
2125 [DefaultValue(null)]
2126 [MWFCategory("Accessibility")]
2127 public string AccessibleName {
2129 if (accessibility_object != null)
2130 return accessibility_object.Name;
2136 if (accessibility_object != null)
2137 accessibility_object.Name = value;
2141 [DefaultValue(AccessibleRole.Default)]
2142 [MWFDescription("Role of the control"), MWFCategory("Accessibility")]
2143 public AccessibleRole AccessibleRole {
2145 if (accessibility_object != null)
2146 return accessibility_object.role;
2148 return AccessibleRole.Default;
2152 if (accessibility_object != null)
2153 accessibility_object.role = value;
2157 [DefaultValue(false)]
2158 [MWFCategory("Behavior")]
2159 public virtual bool AllowDrop {
2165 if (allow_drop == value)
2168 if (IsHandleCreated) {
2170 XplatUI.SetAllowDrop (Handle, value);
2176 [RefreshProperties(RefreshProperties.Repaint)]
2177 [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
2178 [MWFCategory("Layout")]
2179 public virtual AnchorStyles Anchor {
2181 return anchor_style;
2185 layout_type = LayoutType.Anchor;
2187 if (anchor_style == value)
2191 dock_style = DockStyle.None;
2196 parent.PerformLayout(this, "Anchor");
2202 [DefaultValue (typeof (Point), "0, 0")]
2203 [EditorBrowsable (EditorBrowsableState.Advanced)]
2204 public virtual Point AutoScrollOffset {
2206 return auto_scroll_offset;
2210 this.auto_scroll_offset = value;
2214 // XXX: Implement me!
2217 [RefreshProperties (RefreshProperties.All)]
2218 [Localizable (true)]
2219 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
2221 [EditorBrowsable (EditorBrowsableState.Never)]
2222 [DefaultValue (false)]
2223 public virtual bool AutoSize {
2224 get { return auto_size; }
2226 if (this.auto_size != value) {
2229 // If we're turning this off, reset our size
2231 Size = explicit_bounds.Size;
2233 OnAutoSizeChanged (EventArgs.Empty);
2239 [AmbientValue ("{Width=0, Height=0}")]
2241 [AmbientValue (typeof(Size), "0, 0")]
2243 [MWFCategory("Layout")]
2244 public virtual Size MaximumSize {
2246 return maximum_size;
2249 if (maximum_size != value) {
2250 maximum_size = value;
2251 Size = PreferredSize;
2256 internal bool ShouldSerializeMaximumSize ()
2258 return this.MaximumSize != DefaultMaximumSize;
2261 [MWFCategory("Layout")]
2262 public virtual Size MinimumSize {
2264 return minimum_size;
2267 if (minimum_size != value) {
2268 minimum_size = value;
2269 Size = PreferredSize;
2274 internal bool ShouldSerializeMinimumSize ()
2276 return this.MinimumSize != DefaultMinimumSize;
2281 [MWFCategory("Appearance")]
2282 public virtual Color BackColor {
2284 if (background_color.IsEmpty) {
2286 Color pcolor = parent.BackColor;
2287 if (pcolor.A == 0xff || GetStyle(ControlStyles.SupportsTransparentBackColor))
2290 return DefaultBackColor;
2292 return background_color;
2296 if (!value.IsEmpty && (value.A != 0xff) && !GetStyle(ControlStyles.SupportsTransparentBackColor)) {
2297 throw new ArgumentException("Transparent background colors are not supported on this control");
2300 if (background_color != value) {
2301 background_color=value;
2302 SetChildColor(this);
2303 OnBackColorChanged(EventArgs.Empty);
2309 internal bool ShouldSerializeBackColor ()
2311 return this.BackColor != DefaultBackColor;
2315 [DefaultValue(null)]
2316 [MWFCategory("Appearance")]
2317 public virtual Image BackgroundImage {
2319 return background_image;
2323 if (background_image!=value) {
2324 background_image=value;
2325 OnBackgroundImageChanged(EventArgs.Empty);
2332 [DefaultValue (ImageLayout.Tile)]
2333 [Localizable (true)]
2334 [MWFCategory("Appearance")]
2335 public virtual ImageLayout BackgroundImageLayout {
2337 return backgroundimage_layout;
2340 if (Array.IndexOf (Enum.GetValues (typeof (ImageLayout)), value) == -1)
2341 throw new InvalidEnumArgumentException ("value", (int) value, typeof(ImageLayout));
2343 if (value != backgroundimage_layout) {
2344 backgroundimage_layout = value;
2346 OnBackgroundImageLayoutChanged (EventArgs.Empty);
2352 [EditorBrowsable(EditorBrowsableState.Advanced)]
2354 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2355 public virtual BindingContext BindingContext {
2357 if (binding_context != null)
2358 return binding_context;
2361 binding_context = Parent.BindingContext;
2362 return binding_context;
2365 if (binding_context != value) {
2366 binding_context = value;
2367 OnBindingContextChanged(EventArgs.Empty);
2372 [EditorBrowsable(EditorBrowsableState.Advanced)]
2374 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2377 return bounds.Y+bounds.Height;
2381 [EditorBrowsable(EditorBrowsableState.Advanced)]
2383 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2384 public Rectangle Bounds {
2390 SetBounds(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
2394 [EditorBrowsable(EditorBrowsableState.Advanced)]
2396 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2397 public bool CanFocus {
2399 if (IsHandleCreated && Visible && Enabled) {
2406 [EditorBrowsable(EditorBrowsableState.Advanced)]
2408 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2409 public bool CanSelect {
2413 if (!GetStyle(ControlStyles.Selectable)) {
2418 while (parent != null) {
2419 if (!parent.is_visible || !parent.is_enabled) {
2423 parent = parent.parent;
2429 internal virtual bool InternalCapture {
2439 [EditorBrowsable(EditorBrowsableState.Advanced)]
2441 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2442 public bool Capture {
2444 return this.is_captured;
2448 // Call OnMouseCaptureChanged when we get WM_CAPTURECHANGED.
2449 if (value != is_captured) {
2452 XplatUI.GrabWindow(Handle, IntPtr.Zero);
2454 if (IsHandleCreated)
2455 XplatUI.UngrabWindow(Handle);
2456 is_captured = false;
2462 [DefaultValue(true)]
2463 [MWFCategory("Focus")]
2464 public bool CausesValidation {
2466 return this.causes_validation;
2470 if (this.causes_validation != value) {
2471 causes_validation = value;
2472 OnCausesValidationChanged(EventArgs.Empty);
2477 [EditorBrowsable(EditorBrowsableState.Advanced)]
2479 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2480 public Rectangle ClientRectangle {
2482 client_rect.Width = client_size.Width;
2483 client_rect.Height = client_size.Height;
2488 [EditorBrowsable(EditorBrowsableState.Advanced)]
2490 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2491 public Size ClientSize {
2494 if ((this is Form) && (((Form)this).form_parent_window != null)) {
2495 return ((Form)this).form_parent_window.ClientSize;
2503 this.SetClientSizeCore(value.Width, value.Height);
2505 this.OnClientSizeChanged (EventArgs.Empty);
2510 [EditorBrowsable(EditorBrowsableState.Advanced)]
2512 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2513 [DescriptionAttribute("ControlCompanyNameDescr")]
2514 public String CompanyName {
2516 return "Mono Project, Novell, Inc.";
2520 [EditorBrowsable(EditorBrowsableState.Advanced)]
2522 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2523 public bool ContainsFocus {
2525 IntPtr focused_window;
2527 focused_window = XplatUI.GetFocus();
2528 if (IsHandleCreated) {
2529 if (focused_window == Handle) {
2533 for (int i=0; i < child_controls.Count; i++) {
2534 if (child_controls[i].ContainsFocus) {
2545 [DefaultValue(null)]
2546 [MWFCategory("Behavior")]
2547 public virtual ContextMenu ContextMenu {
2549 return ContextMenuInternal;
2553 ContextMenuInternal = value;
2557 internal virtual ContextMenu ContextMenuInternal {
2559 return context_menu;
2562 if (context_menu != value) {
2563 context_menu = value;
2564 OnContextMenuChanged (EventArgs.Empty);
2570 [DefaultValue (null)]
2571 [MWFCategory("Behavior")]
2572 public virtual ContextMenuStrip ContextMenuStrip {
2573 get { return this.context_menu_strip; }
2575 if (this.context_menu_strip != value) {
2576 this.context_menu_strip = value;
2577 OnContextMenuStripChanged (EventArgs.Empty);
2584 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
2585 public ControlCollection Controls {
2587 return this.child_controls;
2591 [EditorBrowsable(EditorBrowsableState.Advanced)]
2593 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2594 public bool Created {
2596 return (!is_disposed && is_created);
2600 [AmbientValue(null)]
2601 [MWFCategory("Appearance")]
2602 public virtual Cursor Cursor {
2605 if (use_wait_cursor)
2606 return Cursors.WaitCursor;
2609 if (cursor != null) {
2613 if (parent != null) {
2614 return parent.Cursor;
2617 return Cursors.Default;
2621 if (cursor == value) {
2628 OnCursorChanged (EventArgs.Empty);
2632 internal bool ShouldSerializeCursor ()
2634 return this.Cursor != Cursors.Default;
2637 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
2638 [ParenthesizePropertyName(true)]
2639 [RefreshProperties(RefreshProperties.All)]
2640 [MWFCategory("Data")]
2641 public ControlBindingsCollection DataBindings {
2643 if (data_bindings == null)
2644 data_bindings = new ControlBindingsCollection (this);
2645 return data_bindings;
2649 [EditorBrowsable(EditorBrowsableState.Advanced)]
2651 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2652 public virtual Rectangle DisplayRectangle {
2654 return ClientRectangle;
2658 [EditorBrowsable(EditorBrowsableState.Advanced)]
2660 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2661 public bool Disposing {
2668 [RefreshProperties(RefreshProperties.Repaint)]
2669 [DefaultValue(DockStyle.None)]
2670 [MWFCategory("Layout")]
2671 public virtual DockStyle Dock {
2677 // If the user sets this to None, we need to still use Anchor layout
2678 if (value != DockStyle.None)
2679 layout_type = LayoutType.Dock;
2681 if (dock_style == value) {
2685 if (!Enum.IsDefined (typeof (DockStyle), value)) {
2686 throw new InvalidEnumArgumentException ("value", (int) value,
2687 typeof (DockStyle));
2691 anchor_style = AnchorStyles.Top | AnchorStyles.Left;
2693 if (dock_style == DockStyle.None) {
2694 bounds = explicit_bounds;
2695 layout_type = LayoutType.Anchor;
2699 parent.PerformLayout(this, "Dock");
2700 else if (Controls.Count > 0)
2703 OnDockChanged(EventArgs.Empty);
2708 protected virtual bool DoubleBuffered {
2710 return (control_style & ControlStyles.OptimizedDoubleBuffer) != 0;
2714 if (value == DoubleBuffered)
2717 SetStyle (ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
2719 SetStyle (ControlStyles.OptimizedDoubleBuffer, false);
2725 public void DrawToBitmap (Bitmap bitmap, Rectangle targetBounds)
2727 Bitmap b = new Bitmap (Width, Height);
2728 Graphics g = Graphics.FromImage (b);
2730 OnPaint (new PaintEventArgs (g, targetBounds));
2732 using (Graphics g2 = Graphics.FromImage (bitmap))
2733 g2.DrawImage (b, targetBounds);
2742 [MWFCategory("Behavior")]
2743 public bool Enabled {
2749 if (parent != null) {
2750 return parent.Enabled;
2757 if (this.is_enabled == value)
2760 bool old_value = is_enabled;
2767 if (old_value != value && !value && this.has_focus)
2768 SelectNextControl(this, true, true, true, true);
2770 OnEnabledChanged (EventArgs.Empty);
2774 internal bool ShouldSerializeEnabled ()
2776 return this.Enabled != true;
2779 [EditorBrowsable(EditorBrowsableState.Advanced)]
2781 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2782 public virtual bool Focused {
2784 return this.has_focus;
2789 [AmbientValue(null)]
2791 [MWFCategory("Appearance")]
2792 public virtual Font Font {
2794 [return: MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof (Font))]
2800 if (parent != null) {
2801 Font f = parent.Font;
2810 [param:MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Font))]
2812 if (font != null && font.Equals (value)) {
2818 OnFontChanged (EventArgs.Empty);
2823 internal bool ShouldSerializeFont ()
2825 return !this.Font.Equals (DefaultFont);
2829 [MWFCategory("Appearance")]
2830 public virtual Color ForeColor {
2832 if (foreground_color.IsEmpty) {
2834 return parent.ForeColor;
2836 return DefaultForeColor;
2838 return foreground_color;
2842 if (foreground_color != value) {
2843 foreground_color=value;
2845 OnForeColorChanged(EventArgs.Empty);
2850 internal bool ShouldSerializeForeColor ()
2852 return this.ForeColor != DefaultForeColor;
2857 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2858 public IntPtr Handle { // IWin32Window
2861 if (verify_thread_handle) {
2862 if (this.InvokeRequired) {
2863 throw new InvalidOperationException("Cross-thread access of handle detected. Handle access only valid on thread that created the control");
2867 if (!IsHandleCreated) {
2870 return window.Handle;
2874 [EditorBrowsable(EditorBrowsableState.Advanced)]
2876 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2877 public bool HasChildren {
2879 if (this.child_controls.Count>0) {
2886 [EditorBrowsable(EditorBrowsableState.Always)]
2888 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2890 get { return this.bounds.Height; }
2891 set { SetBounds(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height); }
2894 [AmbientValue(ImeMode.Inherit)]
2896 [MWFCategory("Behavior")]
2897 public ImeMode ImeMode {
2899 if (ime_mode == ImeMode.Inherit) {
2901 return parent.ImeMode;
2903 return ImeMode.NoControl; // default value
2909 if (ime_mode != value) {
2912 OnImeModeChanged(EventArgs.Empty);
2917 internal bool ShouldSerializeImeMode ()
2919 return this.ImeMode != ImeMode.NoControl;
2922 [EditorBrowsable(EditorBrowsableState.Advanced)]
2924 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2925 public bool InvokeRequired { // ISynchronizeInvoke
2927 if (creator_thread != null && creator_thread!=Thread.CurrentThread) {
2934 [EditorBrowsable(EditorBrowsableState.Advanced)]
2936 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2937 public bool IsAccessible {
2939 return is_accessible;
2943 is_accessible = value;
2947 [EditorBrowsable(EditorBrowsableState.Advanced)]
2949 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2950 public bool IsDisposed {
2952 return this.is_disposed;
2956 [EditorBrowsable(EditorBrowsableState.Advanced)]
2958 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2959 public bool IsHandleCreated {
2961 if (window == null || window.Handle == IntPtr.Zero)
2964 Hwnd hwnd = Hwnd.ObjectFromHandle (window.Handle);
2965 if (hwnd != null && hwnd.zombie)
2973 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2974 [EditorBrowsable(EditorBrowsableState.Advanced)]
2976 [MonoNotSupported ("RTL is not supported")]
2977 public bool IsMirrored {
2978 get { return false; }
2983 [EditorBrowsable (EditorBrowsableState.Advanced)]
2987 Layout.LayoutEngine LayoutEngine {
2989 if (layout_engine == null)
2990 layout_engine = new Layout.DefaultLayout ();
2991 return layout_engine;
2995 [EditorBrowsable(EditorBrowsableState.Always)]
2997 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3000 return this.bounds.X;
3004 SetBounds(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
3009 [MWFCategory("Layout")]
3010 public Point Location {
3012 return new Point(bounds.X, bounds.Y);
3016 SetBounds(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
3020 internal bool ShouldSerializeLocation ()
3022 return this.Location != new Point (0, 0);
3026 [Localizable (true)]
3027 [MWFCategory("Layout")]
3028 public Padding Margin {
3029 get { return this.margin; }
3031 if (this.margin != value) {
3032 this.margin = value;
3033 OnMarginChanged (EventArgs.Empty);
3038 internal bool ShouldSerializeMargin ()
3040 return this.Margin != DefaultMargin;
3045 public string Name {
3057 [MWFCategory("Layout")]
3058 public Padding Padding {
3064 if (padding != value) {
3066 OnPaddingChanged (EventArgs.Empty);
3068 // Changing padding generally requires a new size
3069 if (this.AutoSize && this.Parent != null)
3070 parent.PerformLayout (this, "Padding");
3072 PerformLayout (this, "Padding");
3077 internal bool ShouldSerializePadding ()
3079 return this.Padding != DefaultPadding;
3084 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3085 public Control Parent {
3091 if (value == this) {
3092 throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
3095 if (parent!=value) {
3097 parent.Controls.Remove(this);
3102 value.Controls.Add(this);
3109 public Size PreferredSize {
3110 get { return this.GetPreferredSize (Size.Empty); }
3114 [EditorBrowsable(EditorBrowsableState.Advanced)]
3116 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3117 public string ProductName {
3119 Type t = typeof (AssemblyProductAttribute);
3120 Assembly assembly = GetType().Module.Assembly;
3121 object [] attrs = assembly.GetCustomAttributes (t, false);
3122 AssemblyProductAttribute a = null;
3123 // On MS we get a NullRefException if product attribute is not
3125 if (attrs != null && attrs.Length > 0)
3126 a = (AssemblyProductAttribute) attrs [0];
3128 return GetType ().Namespace;
3134 [EditorBrowsable(EditorBrowsableState.Advanced)]
3136 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3137 public string ProductVersion {
3139 Type t = typeof (AssemblyVersionAttribute);
3140 Assembly assembly = GetType().Module.Assembly;
3141 object [] attrs = assembly.GetCustomAttributes (t, false);
3142 if (attrs == null || attrs.Length < 1)
3144 return ((AssemblyVersionAttribute)attrs [0]).Version;
3148 [EditorBrowsable(EditorBrowsableState.Advanced)]
3150 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3151 public bool RecreatingHandle {
3153 return is_recreating;
3157 [EditorBrowsable(EditorBrowsableState.Advanced)]
3159 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3160 public Region Region {
3166 if (clip_region != value) {
3167 if (IsHandleCreated)
3168 XplatUI.SetClipRegion(Handle, value);
3170 clip_region = value;
3173 OnRegionChanged (EventArgs.Empty);
3179 [EditorBrowsable(EditorBrowsableState.Advanced)]
3181 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3184 return this.bounds.X+this.bounds.Width;
3188 [AmbientValue(RightToLeft.Inherit)]
3190 [MWFCategory("Appearance")]
3191 public virtual RightToLeft RightToLeft {
3193 if (right_to_left == RightToLeft.Inherit) {
3195 return parent.RightToLeft;
3197 return RightToLeft.No; // default value
3199 return right_to_left;
3203 if (value != right_to_left) {
3204 right_to_left = value;
3205 OnRightToLeftChanged(EventArgs.Empty);
3211 internal bool ShouldSerializeRightToLeft ()
3213 return this.RightToLeft != RightToLeft.No;
3216 [EditorBrowsable(EditorBrowsableState.Advanced)]
3217 public override ISite Site {
3225 if (value != null) {
3226 AmbientProperties ap = (AmbientProperties) value.GetService (typeof (AmbientProperties));
3228 BackColor = ap.BackColor;
3229 ForeColor = ap.ForeColor;
3237 internal bool ShouldSerializeSite ()
3243 [MWFCategory("Layout")]
3246 return new Size(Width, Height);
3250 SetBounds(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
3254 internal virtual bool ShouldSerializeSize ()
3256 return this.Size != DefaultSize;
3260 [MergableProperty(false)]
3261 [MWFCategory("Behavior")]
3262 public int TabIndex {
3264 if (tab_index != -1) {
3271 if (tab_index != value) {
3273 OnTabIndexChanged(EventArgs.Empty);
3279 [DefaultValue(true)]
3280 [MWFCategory("Behavior")]
3281 public bool TabStop {
3287 if (tab_stop != value) {
3289 OnTabStopChanged(EventArgs.Empty);
3294 [Localizable(false)]
3296 [TypeConverter(typeof(StringConverter))]
3297 [DefaultValue(null)]
3298 [MWFCategory("Data")]
3305 control_tag = value;
3311 [BindableAttribute(true)]
3312 [MWFCategory("Appearance")]
3313 public virtual string Text {
3315 // Our implementation ignores ControlStyles.CacheText - we always cache
3320 if (value == null) {
3321 value = String.Empty;
3326 UpdateWindowText ();
3327 OnTextChanged (EventArgs.Empty);
3330 // Label has its own AutoSize implementation
3331 if (AutoSize && Parent != null && (!(this is Label)))
3332 Parent.PerformLayout (this, "Text");
3338 internal virtual void UpdateWindowText ()
3340 if (!IsHandleCreated) {
3343 XplatUI.Text (Handle, text);
3346 [EditorBrowsable(EditorBrowsableState.Always)]
3348 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3351 return this.bounds.Y;
3355 SetBounds(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
3359 [EditorBrowsable(EditorBrowsableState.Advanced)]
3361 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3362 public Control TopLevelControl {
3366 while (p.parent != null) {
3370 return p is Form ? p : null;
3375 [EditorBrowsable(EditorBrowsableState.Always)]
3377 [DefaultValue (false)]
3378 [MWFCategory("Appearance")]
3379 public bool UseWaitCursor {
3380 get { return use_wait_cursor; }
3382 if (use_wait_cursor != value) {
3383 use_wait_cursor = value;
3385 OnCursorChanged (EventArgs.Empty);
3392 [MWFCategory("Behavior")]
3393 public bool Visible {
3397 } else if (parent != null) {
3398 return parent.Visible;
3405 if (this.is_visible != value) {
3406 SetVisibleCore(value);
3409 parent.PerformLayout (this, "Visible");
3414 internal bool ShouldSerializeVisible ()
3416 return this.Visible != true;
3419 [EditorBrowsable(EditorBrowsableState.Always)]
3421 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3424 return this.bounds.Width;
3428 SetBounds(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
3432 [EditorBrowsable(EditorBrowsableState.Never)]
3434 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3435 public IWindowTarget WindowTarget {
3436 get { return window_target; }
3437 set { window_target = value; }
3439 #endregion // Public Instance Properties
3441 #region Protected Instance Properties
3443 protected virtual bool CanEnableIme {
3444 get { return false; }
3447 // Is only false in some ActiveX contexts
3448 protected override bool CanRaiseEvents {
3449 get { return true; }
3453 protected virtual CreateParams CreateParams {
3455 CreateParams create_params = new CreateParams();
3458 create_params.Caption = Text;
3461 create_params.Caption = text;
3465 create_params.X = Left;
3468 create_params.X = this.bounds.X;
3472 create_params.Y = Top;
3475 create_params.Y = this.bounds.Y;
3479 create_params.Width = Width;
3482 create_params.Width = this.bounds.Width;
3486 create_params.Height = Height;
3489 create_params.Height = this.bounds.Height;
3493 create_params.ClassName = XplatUI.DefaultClassName;
3494 create_params.ClassStyle = (int)(XplatUIWin32.ClassStyle.CS_OWNDC | XplatUIWin32.ClassStyle.CS_DBLCLKS);
3495 create_params.ExStyle = 0;
3496 create_params.Param = 0;
3499 create_params.ExStyle |= (int)WindowExStyles.WS_EX_ACCEPTFILES;
3502 if ((parent!=null) && (parent.IsHandleCreated)) {
3503 create_params.Parent = parent.Handle;
3506 create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
3509 create_params.Style |= (int)WindowStyles.WS_VISIBLE;
3513 create_params.Style |= (int)WindowStyles.WS_DISABLED;
3516 switch (border_style) {
3517 case BorderStyle.FixedSingle:
3518 create_params.Style |= (int) WindowStyles.WS_BORDER;
3520 case BorderStyle.Fixed3D:
3521 create_params.ExStyle |= (int) WindowExStyles.WS_EX_CLIENTEDGE;
3525 create_params.control = this;
3527 return create_params;
3532 protected virtual Cursor DefaultCursor { get { return Cursors.Default; } }
3535 protected virtual ImeMode DefaultImeMode {
3537 return ImeMode.Inherit;
3542 protected virtual Padding DefaultMargin {
3543 get { return new Padding (3); }
3546 protected virtual Size DefaultMaximumSize { get { return new Size (); } }
3547 protected virtual Size DefaultMinimumSize { get { return new Size (); } }
3548 protected virtual Padding DefaultPadding { get { return new Padding (); } }
3551 protected virtual Size DefaultSize {
3553 return new Size(0, 0);
3557 protected int FontHeight {
3569 protected bool RenderRightToLeft {
3571 return (this.right_to_left == RightToLeft.Yes);
3575 protected bool ResizeRedraw {
3577 return GetStyle(ControlStyles.ResizeRedraw);
3581 SetStyle(ControlStyles.ResizeRedraw, value);
3586 [EditorBrowsable (EditorBrowsableState.Advanced)]
3587 protected virtual bool ScaleChildren {
3588 get { return ScaleChildrenInternal; }
3592 internal virtual bool ScaleChildrenInternal {
3593 get { return true; }
3596 [EditorBrowsable(EditorBrowsableState.Advanced)]
3598 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3599 protected internal virtual bool ShowFocusCues {
3602 return show_focus_cues;
3604 if (this.parent == null)
3607 Form f = this.FindForm ();
3610 return f.show_focus_cues;
3616 [EditorBrowsable(EditorBrowsableState.Advanced)]
3618 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3622 protected bool ShowKeyboardCues {
3624 return ShowKeyboardCuesInternal;
3628 internal bool ShowKeyboardCuesInternal {
3630 if (SystemInformation.MenuAccessKeysUnderlined || DesignMode)
3633 return show_keyboard_cues;
3637 #endregion // Protected Instance Properties
3639 #region Public Static Methods
3640 [EditorBrowsable(EditorBrowsableState.Advanced)]
3641 public static Control FromChildHandle(IntPtr handle) {
3642 return Control.ControlNativeWindow.ControlFromChildHandle (handle);
3645 [EditorBrowsable(EditorBrowsableState.Advanced)]
3646 public static Control FromHandle(IntPtr handle) {
3647 return Control.ControlNativeWindow.ControlFromHandle(handle);
3651 [MonoTODO ("Only implemented for Win32, others always return false")]
3652 public static bool IsKeyLocked (Keys keyVal)
3658 return XplatUI.IsKeyLocked ((VirtualKeys)keyVal);
3660 throw new NotSupportedException ("keyVal must be CapsLock, NumLock, or ScrollLock");
3665 public static bool IsMnemonic(char charCode, string text) {
3668 amp = text.IndexOf('&');
3671 if (amp + 1 < text.Length) {
3672 if (text[amp + 1] != '&') {
3673 if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
3683 #region Protected Static Methods
3684 [EditorBrowsable(EditorBrowsableState.Advanced)]
3685 protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
3688 c = Control.FromHandle(hWnd);
3698 #region Public Instance Methods
3699 [EditorBrowsable(EditorBrowsableState.Advanced)]
3700 public IAsyncResult BeginInvoke(Delegate method) {
3701 object [] prms = null;
3702 if (method is EventHandler)
3703 prms = new object [] { this, EventArgs.Empty };
3704 return BeginInvokeInternal(method, prms);
3707 [EditorBrowsable(EditorBrowsableState.Advanced)]
3709 public IAsyncResult BeginInvoke (Delegate method, params object[] args)
3711 public IAsyncResult BeginInvoke (Delegate method, object[] args)
3714 return BeginInvokeInternal (method, args);
3717 public void BringToFront() {
3718 if (parent != null) {
3719 parent.child_controls.SetChildIndex(this, 0);
3721 else if (IsHandleCreated) {
3722 XplatUI.SetZOrder(Handle, IntPtr.Zero, false, false);
3726 public bool Contains(Control ctl) {
3727 while (ctl != null) {
3736 public void CreateControl () {
3749 if (parent != null && !parent.Created) {
3753 if (!IsHandleCreated) {
3760 // Create all of our children (implicit ones as well) when we are created.
3761 // The child should fire it's OnLoad before the parents, however
3762 // if the child checks Parent.Created in it's OnCreateControl, the
3763 // parent is already created.
3764 foreach (Control c in Controls.GetAllControls ())
3765 if (!c.Created && !c.IsDisposed)
3769 if (binding_context == null && parent != null) {
3770 OnBindingContextChanged(EventArgs.Empty);
3778 public Graphics CreateGraphics() {
3779 if (!IsHandleCreated) {
3780 this.CreateHandle();
3782 return Graphics.FromHwnd(this.window.Handle);
3785 public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
3786 DragDropEffects result = DragDropEffects.None;
3787 if (IsHandleCreated)
3788 result = XplatUI.StartDrag(Handle, data, allowedEffects);
3789 OnDragDropEnd (result);
3793 internal virtual void OnDragDropEnd (DragDropEffects effects)
3797 [EditorBrowsable(EditorBrowsableState.Advanced)]
3798 public object EndInvoke (IAsyncResult asyncResult) {
3799 AsyncMethodResult result = (AsyncMethodResult) asyncResult;
3800 return result.EndInvoke ();
3803 internal Control FindRootParent ()
3807 while (c.Parent != null)
3813 public Form FindForm() {
3826 [EditorBrowsable (EditorBrowsableState.Advanced)]
3828 public bool Focus() {
3829 return FocusInternal (false);
3832 internal virtual bool FocusInternal (bool skip_check) {
3833 if (skip_check || (CanFocus && IsHandleCreated && !has_focus && !is_focusing)) {
3836 is_focusing = false;
3841 internal Control GetRealChildAtPoint (Point pt) {
3842 if (!IsHandleCreated)
3845 foreach (Control control in child_controls.GetAllControls ()) {
3846 if (control.Bounds.Contains (PointToClient (pt))) {
3847 Control child = control.GetRealChildAtPoint (pt);
3858 public Control GetChildAtPoint(Point pt)
3860 return GetChildAtPoint (pt, GetChildAtPointSkip.None);
3866 Control GetChildAtPoint (Point pt, GetChildAtPointSkip skipValue)
3868 // MS's version causes the handle to be created. The stack trace shows that get_Handle is called here, but
3869 // we'll just call CreateHandle instead.
3870 if (!IsHandleCreated)
3873 // Microsoft's version of this function doesn't seem to work, so I can't check
3874 // if we only consider children or also grandchildren, etc.
3875 // I'm gonna say 'children only'
3876 foreach (Control child in Controls) {
3877 if ((skipValue & GetChildAtPointSkip.Disabled) == GetChildAtPointSkip.Disabled && !child.Enabled)
3879 else if ((skipValue & GetChildAtPointSkip.Invisible) == GetChildAtPointSkip.Invisible && !child.Visible)
3881 else if ((skipValue & GetChildAtPointSkip.Transparent) == GetChildAtPointSkip.Transparent && child.BackColor.A == 0x0)
3883 else if (child.Bounds.Contains (pt))
3890 public IContainerControl GetContainerControl() {
3891 Control current = this;
3893 while (current!=null) {
3894 if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
3895 return (IContainerControl)current;
3897 current = current.parent;
3902 internal ContainerControl InternalGetContainerControl() {
3903 Control current = this;
3905 while (current!=null) {
3906 if ((current is ContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
3907 return current as ContainerControl;
3909 current = current.parent;
3914 public Control GetNextControl(Control ctl, bool forward) {
3916 if (!this.Contains(ctl)) {
3921 ctl = FindControlForward(this, ctl);
3924 ctl = FindControlBackward(this, ctl);
3934 [EditorBrowsable (EditorBrowsableState.Advanced)]
3935 public virtual Size GetPreferredSize (Size proposedSize) {
3936 Size retsize = GetPreferredSizeCore (proposedSize);
3938 // If we're bigger than the MaximumSize, fix that
3939 if (this.maximum_size.Width != 0 && retsize.Width > this.maximum_size.Width)
3940 retsize.Width = this.maximum_size.Width;
3941 if (this.maximum_size.Height != 0 && retsize.Height > this.maximum_size.Height)
3942 retsize.Height = this.maximum_size.Height;
3944 // If we're smaller than the MinimumSize, fix that
3945 if (this.minimum_size.Width != 0 && retsize.Width < this.minimum_size.Width)
3946 retsize.Width = this.minimum_size.Width;
3947 if (this.minimum_size.Height != 0 && retsize.Height < this.minimum_size.Height)
3948 retsize.Height = this.minimum_size.Height;
3954 public void Hide() {
3955 this.Visible = false;
3958 public void Invalidate() {
3959 Invalidate(ClientRectangle, false);
3962 public void Invalidate(bool invalidateChildren) {
3963 Invalidate(ClientRectangle, invalidateChildren);
3966 public void Invalidate(System.Drawing.Rectangle rc) {
3967 Invalidate(rc, false);
3970 public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
3971 // Win32 invalidates control including when Width and Height is equal 0
3972 // or is not visible, only Paint event must be care about this.
3973 if (!IsHandleCreated)
3976 if (rc == Rectangle.Empty)
3977 rc = ClientRectangle;
3979 if (rc.Width > 0 && rc.Height > 0) {
3981 NotifyInvalidate(rc);
3983 XplatUI.Invalidate(Handle, rc, false);
3985 if (invalidateChildren) {
3986 Control [] controls = child_controls.GetAllControls ();
3987 for (int i=0; i<controls.Length; i++)
3988 controls [i].Invalidate ();
3990 // If any of our children are transparent, we
3991 // have to invalidate them anyways
3992 foreach (Control c in Controls)
3993 if (c.BackColor.A != 255)
3997 OnInvalidated(new InvalidateEventArgs(rc));
4000 public void Invalidate(System.Drawing.Region region) {
4001 Invalidate(region, false);
4004 public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
4005 RectangleF bounds = region.GetBounds (CreateGraphics ());
4006 Invalidate (new Rectangle ((int) bounds.X, (int) bounds.Y, (int) bounds.Width, (int) bounds.Height),
4007 invalidateChildren);
4010 public object Invoke (Delegate method) {
4011 object [] prms = null;
4012 if (method is EventHandler)
4013 prms = new object [] { this, EventArgs.Empty };
4015 return Invoke(method, prms);
4018 public object Invoke (Delegate method, params object [] args) {
4020 public object Invoke (Delegate method, object[] args) {
4022 Control control = FindControlToInvokeOn ();
4024 if (!this.InvokeRequired) {
4025 return method.DynamicInvoke(args);
4028 IAsyncResult result = BeginInvokeInternal (method, args, control);
4029 return EndInvoke(result);
4032 [EditorBrowsable(EditorBrowsableState.Advanced)]
4033 public void PerformLayout() {
4034 PerformLayout(null, null);
4037 [EditorBrowsable(EditorBrowsableState.Advanced)]
4038 public void PerformLayout(Control affectedControl, string affectedProperty) {
4039 LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
4041 foreach (Control c in Controls.GetAllControls ())
4042 if (c.recalculate_distances)
4043 c.UpdateDistances ();
4045 if (layout_suspended > 0) {
4046 layout_pending = true;
4050 layout_pending = false;
4052 // Prevent us from getting messed up
4055 // Perform all Dock and Anchor calculations
4060 // Need to make sure we decremend layout_suspended
4066 public Point PointToClient (Point p) {
4070 XplatUI.ScreenToClient (Handle, ref x, ref y);
4072 return new Point (x, y);
4075 public Point PointToScreen(Point p) {
4079 XplatUI.ClientToScreen(Handle, ref x, ref y);
4081 return new Point(x, y);
4085 [EditorBrowsable(EditorBrowsableState.Advanced)]
4086 public PreProcessControlState PreProcessControlMessage (ref Message msg)
4088 return PreProcessControlMessageInternal (ref msg);
4092 internal PreProcessControlState PreProcessControlMessageInternal (ref Message msg)
4094 switch ((Msg)msg.Msg) {
4095 case Msg.WM_KEYDOWN:
4096 case Msg.WM_SYSKEYDOWN:
4098 PreviewKeyDownEventArgs e = new PreviewKeyDownEventArgs ((Keys)msg.WParam.ToInt32 () | XplatUI.State.ModifierKeys);
4099 OnPreviewKeyDown (e);
4102 return PreProcessControlState.MessageNeeded;
4105 if (PreProcessMessage (ref msg))
4106 return PreProcessControlState.MessageProcessed;
4108 if (IsInputKey ((Keys)msg.WParam.ToInt32 () | XplatUI.State.ModifierKeys))
4109 return PreProcessControlState.MessageNeeded;
4113 case Msg.WM_SYSCHAR:
4114 if (PreProcessMessage (ref msg))
4115 return PreProcessControlState.MessageProcessed;
4117 if (IsInputChar ((char)msg.WParam))
4118 return PreProcessControlState.MessageNeeded;
4125 return PreProcessControlState.MessageNotNeeded;
4128 public virtual bool PreProcessMessage (ref Message msg)
4130 return InternalPreProcessMessage (ref msg);
4133 internal virtual bool InternalPreProcessMessage (ref Message msg) {
4136 if ((msg.Msg == (int)Msg.WM_KEYDOWN) || (msg.Msg == (int)Msg.WM_SYSKEYDOWN)) {
4137 key_data = (Keys)msg.WParam.ToInt32() | XplatUI.State.ModifierKeys;
4139 if (!ProcessCmdKey(ref msg, key_data)) {
4140 if (IsInputKey(key_data)) {
4144 return ProcessDialogKey(key_data);
4148 } else if (msg.Msg == (int)Msg.WM_CHAR) {
4149 if (IsInputChar((char)msg.WParam)) {
4152 return ProcessDialogChar((char)msg.WParam);
4153 } else if (msg.Msg == (int)Msg.WM_SYSCHAR) {
4154 if (ProcessDialogChar((char)msg.WParam))
4158 return ToolStripManager.ProcessMenuKey (ref msg);
4166 public Rectangle RectangleToClient(Rectangle r) {
4167 return new Rectangle(PointToClient(r.Location), r.Size);
4170 public Rectangle RectangleToScreen(Rectangle r) {
4171 return new Rectangle(PointToScreen(r.Location), r.Size);
4174 public virtual void Refresh() {
4175 if (IsHandleCreated && Visible) {
4177 XplatUI.UpdateWindow(window.Handle);
4179 Control [] controls = child_controls.GetAllControls ();
4180 for (int i=0; i < controls.Length; i++) {
4181 controls[i].Refresh();
4187 [EditorBrowsable(EditorBrowsableState.Never)]
4188 public virtual void ResetBackColor() {
4189 BackColor = Color.Empty;
4192 [EditorBrowsable(EditorBrowsableState.Never)]
4193 public void ResetBindings() {
4194 if (data_bindings != null)
4195 data_bindings.Clear();
4198 [EditorBrowsable(EditorBrowsableState.Never)]
4199 public virtual void ResetCursor() {
4203 [EditorBrowsable(EditorBrowsableState.Never)]
4204 public virtual void ResetFont() {
4208 [EditorBrowsable(EditorBrowsableState.Never)]
4209 public virtual void ResetForeColor() {
4210 foreground_color = Color.Empty;
4213 [EditorBrowsable(EditorBrowsableState.Never)]
4214 public void ResetImeMode() {
4215 ime_mode = DefaultImeMode;
4218 [EditorBrowsable(EditorBrowsableState.Never)]
4219 public virtual void ResetRightToLeft() {
4220 right_to_left = RightToLeft.Inherit;
4223 public virtual void ResetText() {
4224 text = String.Empty;
4227 public void ResumeLayout() {
4228 ResumeLayout (true);
4231 public void ResumeLayout(bool performLayout) {
4232 if (layout_suspended > 0) {
4236 if (layout_suspended == 0) {
4238 if (this is ContainerControl)
4239 (this as ContainerControl).PerformDelayedAutoScale();
4243 foreach (Control c in Controls.GetAllControls ())
4244 c.UpdateDistances ();
4246 if (performLayout && layout_pending) {
4252 [EditorBrowsable (EditorBrowsableState.Never)]
4255 public void Scale(float ratio) {
4256 ScaleCore(ratio, ratio);
4260 [EditorBrowsable (EditorBrowsableState.Never)]
4263 public void Scale(float dx, float dy) {
4268 [EditorBrowsable (EditorBrowsableState.Advanced)]
4269 public void Scale (SizeF factor)
4271 BoundsSpecified bounds_spec = BoundsSpecified.All;
4275 if (this is ContainerControl) {
4276 if ((this as ContainerControl).IsAutoScaling)
4277 bounds_spec = BoundsSpecified.Size;
4278 else if (IsContainerAutoScaling (this.Parent))
4279 bounds_spec = BoundsSpecified.Location;
4282 ScaleControl (factor, bounds_spec);
4285 if ((bounds_spec != BoundsSpecified.Location) && ScaleChildren) {
4286 foreach (Control c in Controls.GetAllControls ()) {
4288 if (c is ContainerControl) {
4289 ContainerControl cc = c as ContainerControl;
4290 if ((cc.AutoScaleMode == AutoScaleMode.Inherit) && IsContainerAutoScaling (this))
4291 cc.PerformAutoScale (true);
4299 internal ContainerControl FindContainer (Control c)
4301 while ((c != null) && !(c is ContainerControl))
4303 return c as ContainerControl;
4306 private bool IsContainerAutoScaling (Control c)
4308 ContainerControl cc = FindContainer (c);
4309 return (cc != null) && cc.IsAutoScaling;
4313 public void Select() {
4314 Select(false, false);
4318 private void printTree(Control c, string t) {
4319 foreach(Control i in c.child_controls) {
4320 Console.WriteLine ("{2}{0}.TabIndex={1}", i, i.tab_index, t);
4321 printTree (i, t+"\t");
4325 public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
4329 Console.WriteLine("{0}", this.FindForm());
4330 printTree(this, "\t");
4333 if (!this.Contains(ctl) || (!nested && (ctl.parent != this))) {
4338 c = GetNextControl(c, forward);
4348 Console.WriteLine("{0} {1}", c, c.CanSelect);
4350 if (c.CanSelect && ((c.parent == this) || nested) && (c.tab_stop || !tabStopOnly)) {
4351 c.Select (true, true);
4354 } while (c != ctl); // If we wrap back to ourselves we stop
4359 public void SendToBack() {
4360 if (parent != null) {
4361 parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
4365 public void SetBounds(int x, int y, int width, int height) {
4366 SetBounds(x, y, width, height, BoundsSpecified.All);
4369 public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
4370 // Fill in the values that were not specified
4371 if ((specified & BoundsSpecified.X) == 0)
4373 if ((specified & BoundsSpecified.Y) == 0)
4375 if ((specified & BoundsSpecified.Width) == 0)
4377 if ((specified & BoundsSpecified.Height) == 0)
4380 SetBoundsInternal (x, y, width, height, specified);
4383 internal void SetBoundsInternal (int x, int y, int width, int height, BoundsSpecified specified)
4385 // SetBoundsCore is really expensive to call, so we want to avoid it if we can.
4386 // We can avoid it if:
4387 // - The requested dimensions are the same as our current dimensions
4389 // - Any BoundsSpecified is the same as our current explicit_size
4390 if (bounds.X != x || (explicit_bounds.X != x && (specified & BoundsSpecified.X) == BoundsSpecified.X))
4391 SetBoundsCore (x, y, width, height, specified);
4392 else if (bounds.Y != y || (explicit_bounds.Y != y && (specified & BoundsSpecified.Y) == BoundsSpecified.Y))
4393 SetBoundsCore (x, y, width, height, specified);
4394 else if (bounds.Width != width || (explicit_bounds.Width != width && (specified & BoundsSpecified.Width) == BoundsSpecified.Width))
4395 SetBoundsCore (x, y, width, height, specified);
4396 else if (bounds.Height != height || (explicit_bounds.Height != height && (specified & BoundsSpecified.Height) == BoundsSpecified.Height))
4397 SetBoundsCore (x, y, width, height, specified);
4401 // If the user explicitly moved or resized us, recalculate our anchor distances
4402 if (specified != BoundsSpecified.None)
4406 parent.PerformLayout(this, "Bounds");
4409 public void Show () {
4410 this.Visible = true;
4413 public void SuspendLayout() {
4417 public void Update() {
4418 if (IsHandleCreated) {
4419 XplatUI.UpdateWindow(window.Handle);
4422 #endregion // Public Instance Methods
4424 #region Protected Instance Methods
4425 [EditorBrowsable(EditorBrowsableState.Advanced)]
4426 protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
4427 // turns out this method causes handle
4428 // creation in 1.1. at first I thought this
4429 // would be accomplished just by using
4430 // get_AccessibilityObject, which would route
4431 // through CreateAccessibilityInstance, which
4432 // calls CreateControl. This isn't the case,
4433 // though (as overriding
4434 // CreateAccessibilityInstance and adding a
4435 // CWL shows nothing. So we fudge it and put
4436 // a CreateHandle here.
4442 if (accessibility_object != null && accessibility_object is ControlAccessibleObject)
4443 ((ControlAccessibleObject)accessibility_object).NotifyClients (accEvent, childID);
4447 [EditorBrowsable (EditorBrowsableState.Advanced)]
4448 protected void AccessibilityNotifyClients (AccessibleEvents accEvent, int objectID, int childID)
4450 if (accessibility_object != null && accessibility_object is ControlAccessibleObject)
4451 ((ControlAccessibleObject)accessibility_object).NotifyClients (accEvent, objectID, childID);
4455 [EditorBrowsable(EditorBrowsableState.Advanced)]
4456 protected virtual AccessibleObject CreateAccessibilityInstance() {
4458 return new Control.ControlAccessibleObject(this);
4461 [EditorBrowsable(EditorBrowsableState.Advanced)]
4462 protected virtual ControlCollection CreateControlsInstance() {
4463 return new ControlCollection(this);
4466 [EditorBrowsable(EditorBrowsableState.Advanced)]
4467 protected virtual void CreateHandle() {
4469 throw new ObjectDisposedException(GetType().FullName);
4472 if (IsHandleCreated && !is_recreating) {
4476 CreateParams create_params = CreateParams;
4477 window.CreateHandle(create_params);
4479 if (window.Handle != IntPtr.Zero) {
4480 creator_thread = Thread.CurrentThread;
4482 XplatUI.EnableWindow(window.Handle, is_enabled);
4484 if (clip_region != null) {
4485 XplatUI.SetClipRegion(window.Handle, clip_region);
4488 // Set our handle with our parent
4489 if ((parent != null) && (parent.IsHandleCreated)) {
4490 XplatUI.SetParent(window.Handle, parent.Handle);
4494 XplatUI.SetAllowDrop (window.Handle, allow_drop);
4496 // Find out where the window manager placed us
4497 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) != 0) {
4498 XplatUI.SetBorderStyle(window.Handle, (FormBorderStyle)border_style);
4501 Rectangle save_bounds = explicit_bounds;
4503 explicit_bounds = save_bounds;
4507 [EditorBrowsable(EditorBrowsableState.Advanced)]
4508 protected virtual void DefWndProc(ref Message m) {
4509 window.DefWndProc(ref m);
4512 [EditorBrowsable(EditorBrowsableState.Advanced)]
4513 protected virtual void DestroyHandle() {
4514 if (IsHandleCreated) {
4515 if (window != null) {
4516 window.DestroyHandle();
4522 protected virtual AccessibleObject GetAccessibilityObjectById (int objectId)
4524 // XXX need to implement this.
4528 protected internal AutoSizeMode GetAutoSizeMode ()
4530 return auto_size_mode;
4533 [EditorBrowsable (EditorBrowsableState.Advanced)]
4534 protected virtual Rectangle GetScaledBounds (Rectangle bounds, SizeF factor, BoundsSpecified specified)
4536 // Top level controls do not scale location
4538 if ((specified & BoundsSpecified.X) == BoundsSpecified.X)
4539 bounds.X = (int)Math.Round (bounds.X * factor.Width);
4540 if ((specified & BoundsSpecified.Y) == BoundsSpecified.Y)
4541 bounds.Y = (int)Math.Round (bounds.Y * factor.Height);
4544 if ((specified & BoundsSpecified.Width) == BoundsSpecified.Width && !GetStyle (ControlStyles.FixedWidth)) {
4545 int border = (this is ComboBox) ? (ThemeEngine.Current.Border3DSize.Width * 2) :
4546 (this.bounds.Width - this.client_size.Width);
4547 bounds.Width = (int)Math.Round ((bounds.Width - border) * factor.Width + border);
4549 if ((specified & BoundsSpecified.Height) == BoundsSpecified.Height && !GetStyle (ControlStyles.FixedHeight)) {
4550 int border = (this is ComboBox) ? (ThemeEngine.Current.Border3DSize.Height * 2) :
4551 (this.bounds.Height - this.client_size.Height);
4552 bounds.Height = (int)Math.Round ((bounds.Height - border) * factor.Height + border);
4559 private Rectangle GetScaledBoundsOld (Rectangle bounds, SizeF factor, BoundsSpecified specified)
4561 RectangleF new_bounds = new RectangleF(bounds.Location, bounds.Size);
4563 // Top level controls do not scale location
4565 if ((specified & BoundsSpecified.X) == BoundsSpecified.X)
4566 new_bounds.X *= factor.Width;
4567 if ((specified & BoundsSpecified.Y) == BoundsSpecified.Y)
4568 new_bounds.Y *= factor.Height;
4571 if ((specified & BoundsSpecified.Width) == BoundsSpecified.Width && !GetStyle (ControlStyles.FixedWidth)) {
4572 int border = (this is Form) ? (this.bounds.Width - this.client_size.Width) : 0;
4573 new_bounds.Width = ((new_bounds.Width - border) * factor.Width + border);
4575 if ((specified & BoundsSpecified.Height) == BoundsSpecified.Height && !GetStyle (ControlStyles.FixedHeight)) {
4576 int border = (this is Form) ? (this.bounds.Height - this.client_size.Height) : 0;
4577 new_bounds.Height = ((new_bounds.Height - border) * factor.Height + border);
4580 bounds.X = (int)Math.Round (new_bounds.X);
4581 bounds.Y = (int)Math.Round (new_bounds.Y);
4582 bounds.Width = (int)Math.Round (new_bounds.Right) - bounds.X;
4583 bounds.Height = (int)Math.Round (new_bounds.Bottom) - bounds.Y;
4588 protected internal bool GetStyle(ControlStyles flag) {
4589 return (control_style & flag) != 0;
4592 protected bool GetTopLevel() {
4596 [EditorBrowsable(EditorBrowsableState.Advanced)]
4597 protected virtual void InitLayout() {
4600 [EditorBrowsable(EditorBrowsableState.Advanced)]
4601 protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
4602 toInvoke.OnGotFocus(e);
4605 [EditorBrowsable(EditorBrowsableState.Advanced)]
4606 protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
4607 toInvoke.OnLostFocus(e);
4610 [EditorBrowsable(EditorBrowsableState.Advanced)]
4611 protected void InvokeOnClick(Control toInvoke, EventArgs e) {
4612 toInvoke.OnClick(e);
4615 protected void InvokePaint(Control c, PaintEventArgs e) {
4619 protected void InvokePaintBackground(Control c, PaintEventArgs e) {
4620 c.OnPaintBackground (e);
4623 protected virtual bool IsInputChar (char charCode) {
4624 // XXX on MS.NET this method causes the handle to be created..
4625 if (!IsHandleCreated)
4628 return IsInputCharInternal (charCode);
4631 internal virtual bool IsInputCharInternal (char charCode) {
4635 protected virtual bool IsInputKey (Keys keyData) {
4636 // Doc says this one calls IsInputChar; not sure what to do with that
4640 [EditorBrowsable(EditorBrowsableState.Advanced)]
4641 protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
4645 protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
4646 if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
4650 if (parent != null) {
4651 return parent.ProcessCmdKey(ref msg, keyData);
4657 protected virtual bool ProcessDialogChar(char charCode) {
4658 if (parent != null) {
4659 return parent.ProcessDialogChar (charCode);
4665 protected virtual bool ProcessDialogKey (Keys keyData) {
4666 if (parent != null) {
4667 return parent.ProcessDialogKey (keyData);
4673 protected virtual bool ProcessKeyEventArgs (ref Message m)
4675 KeyEventArgs key_event;
4678 case (int)Msg.WM_SYSKEYDOWN:
4679 case (int)Msg.WM_KEYDOWN: {
4680 key_event = new KeyEventArgs ((Keys) m.WParam.ToInt32 ());
4681 OnKeyDown (key_event);
4683 suppressing_key_press = key_event.SuppressKeyPress;
4685 return key_event.Handled;
4688 case (int)Msg.WM_SYSKEYUP:
4689 case (int)Msg.WM_KEYUP: {
4690 key_event = new KeyEventArgs ((Keys) m.WParam.ToInt32 ());
4691 OnKeyUp (key_event);
4692 return key_event.Handled;
4695 case (int)Msg.WM_SYSCHAR:
4696 case (int)Msg.WM_CHAR: {
4698 if (suppressing_key_press)
4701 KeyPressEventArgs key_press_event;
4703 key_press_event = new KeyPressEventArgs ((char) m.WParam);
4704 OnKeyPress(key_press_event);
4706 m.WParam = (IntPtr) key_press_event.KeyChar;
4708 return key_press_event.Handled;
4719 protected internal virtual bool ProcessKeyMessage (ref Message m)
4721 if (parent != null) {
4722 if (parent.ProcessKeyPreview (ref m))
4726 return ProcessKeyEventArgs (ref m);
4729 protected virtual bool ProcessKeyPreview (ref Message m) {
4731 return parent.ProcessKeyPreview(ref m);
4736 protected virtual bool ProcessMnemonic(char charCode) {
4741 [EditorBrowsable(EditorBrowsableState.Advanced)]
4742 protected void RaiseDragEvent(object key, DragEventArgs e) {
4746 [EditorBrowsable(EditorBrowsableState.Advanced)]
4747 protected void RaiseKeyEvent(object key, KeyEventArgs e) {
4751 [EditorBrowsable(EditorBrowsableState.Advanced)]
4752 protected void RaiseMouseEvent(object key, MouseEventArgs e) {
4756 [EditorBrowsable(EditorBrowsableState.Advanced)]
4757 protected void RaisePaintEvent(object key, PaintEventArgs e) {
4761 private void SetIsRecreating () {
4764 foreach (Control c in Controls.GetAllControls()) {
4765 c.SetIsRecreating ();
4769 [EditorBrowsable(EditorBrowsableState.Advanced)]
4770 protected void RecreateHandle() {
4771 if (!IsHandleCreated)
4775 Console.WriteLine("Recreating control {0}", XplatUI.Window(window.Handle));
4780 if (IsHandleCreated) {
4782 Console.WriteLine(" + handle is created, destroying it.");
4785 // WM_DESTROY will CreateHandle for us
4788 Console.WriteLine(" + handle is not created, creating it.");
4796 is_recreating = false;
4798 Console.WriteLine (" + new handle = {0:X}", Handle.ToInt32());
4804 [EditorBrowsable(EditorBrowsableState.Advanced)]
4805 protected void ResetMouseEventArgs() {
4809 [EditorBrowsable(EditorBrowsableState.Advanced)]
4810 protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
4811 if (right_to_left == RightToLeft.No) {
4816 case ContentAlignment.TopLeft: {
4817 return ContentAlignment.TopRight;
4820 case ContentAlignment.TopRight: {
4821 return ContentAlignment.TopLeft;
4824 case ContentAlignment.MiddleLeft: {
4825 return ContentAlignment.MiddleRight;
4828 case ContentAlignment.MiddleRight: {
4829 return ContentAlignment.MiddleLeft;
4832 case ContentAlignment.BottomLeft: {
4833 return ContentAlignment.BottomRight;
4836 case ContentAlignment.BottomRight: {
4837 return ContentAlignment.BottomLeft;
4841 // if it's center it doesn't change
4847 [EditorBrowsable(EditorBrowsableState.Advanced)]
4848 protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
4849 if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
4853 if (align == HorizontalAlignment.Left) {
4854 return HorizontalAlignment.Right;
4857 // align must be HorizontalAlignment.Right
4858 return HorizontalAlignment.Left;
4861 [EditorBrowsable(EditorBrowsableState.Advanced)]
4862 protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
4863 if (right_to_left == RightToLeft.No) {
4867 if (align == LeftRightAlignment.Left) {
4868 return LeftRightAlignment.Right;
4871 // align must be LeftRightAlignment.Right;
4872 return LeftRightAlignment.Left;
4875 [EditorBrowsable(EditorBrowsableState.Advanced)]
4876 protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
4877 return RtlTranslateAlignment(align);
4880 [EditorBrowsable(EditorBrowsableState.Advanced)]
4881 protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
4882 return RtlTranslateAlignment(align);
4885 [EditorBrowsable(EditorBrowsableState.Advanced)]
4886 protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
4887 return RtlTranslateAlignment(align);
4891 [EditorBrowsable (EditorBrowsableState.Advanced)]
4892 protected virtual void ScaleControl (SizeF factor, BoundsSpecified specified)
4894 Rectangle new_bounds = GetScaledBounds (bounds, factor, specified);
4896 SetBounds (new_bounds.X, new_bounds.Y, new_bounds.Width, new_bounds.Height, specified);
4901 [EditorBrowsable (EditorBrowsableState.Never)]
4903 [EditorBrowsable (EditorBrowsableState.Advanced)]
4905 protected virtual void ScaleCore (float dx, float dy)
4907 Rectangle new_bounds = GetScaledBoundsOld (bounds, new SizeF (dx, dy), BoundsSpecified.All);
4911 SetBounds (new_bounds.X, new_bounds.Y, new_bounds.Width, new_bounds.Height, BoundsSpecified.All);
4913 if (ScaleChildrenInternal)
4914 foreach (Control c in Controls.GetAllControls ())
4920 protected virtual void Select(bool directed, bool forward) {
4921 IContainerControl container;
4923 container = GetContainerControl();
4924 if (container != null && (Control)container != this)
4925 container.ActiveControl = this;
4929 protected void SetAutoSizeMode (AutoSizeMode mode)
4931 if (auto_size_mode != mode) {
4932 auto_size_mode = mode;
4933 PerformLayout (this, "AutoSizeMode");
4938 [EditorBrowsable(EditorBrowsableState.Advanced)]
4939 protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
4940 SetBoundsCoreInternal (x, y, width, height, specified);
4943 internal virtual void SetBoundsCoreInternal(int x, int y, int width, int height, BoundsSpecified specified) {
4944 // Nasty hack for 2.0 DateTimePicker
4945 height = OverrideHeight (height);
4947 Rectangle old_explicit = explicit_bounds;
4948 Rectangle new_bounds = new Rectangle (x, y, width, height);
4950 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
4951 if (IsHandleCreated) {
4952 XplatUI.SetWindowPos(Handle, x, y, width, height);
4954 // Win32 automatically changes negative width/height to 0.
4955 // The control has already been sent a WM_WINDOWPOSCHANGED message and it has the correct
4956 // data, but it'll be overwritten when we call UpdateBounds unless we get the updated
4959 XplatUI.GetWindowPos(Handle, this is Form, out ix, out iy, out width, out height, out cw, out ch);
4962 // BoundsSpecified tells us which variables were programatic (user-set).
4963 // We need to store those in the explicit bounds
4964 if ((specified & BoundsSpecified.X) == BoundsSpecified.X)
4965 explicit_bounds.X = new_bounds.X;
4967 explicit_bounds.X = old_explicit.X;
4969 if ((specified & BoundsSpecified.Y) == BoundsSpecified.Y)
4970 explicit_bounds.Y = new_bounds.Y;
4972 explicit_bounds.Y = old_explicit.Y;
4974 if ((specified & BoundsSpecified.Width) == BoundsSpecified.Width)
4975 explicit_bounds.Width = new_bounds.Width;
4977 explicit_bounds.Width = old_explicit.Width;
4979 if ((specified & BoundsSpecified.Height) == BoundsSpecified.Height)
4980 explicit_bounds.Height = new_bounds.Height;
4982 explicit_bounds.Height = old_explicit.Height;
4984 // We need to store the explicit bounds because UpdateBounds is always going
4985 // to change it, and we have to fix it. However, UpdateBounds also calls
4986 // OnLocationChanged, OnSizeChanged, and OnClientSizeChanged. The user can
4987 // override those or use those events to change the size explicitly, and we
4988 // can't undo those changes. So if the bounds after calling UpdateBounds are
4989 // the same as the ones we sent it, we need to fix the explicit bounds. If
4990 // it's not the same as we sent UpdateBounds, then someone else changed it, and
4991 // we better not mess it up. Fun stuff.
4992 Rectangle stored_explicit_bounds = explicit_bounds;
4994 UpdateBounds(x, y, width, height);
4996 if (explicit_bounds.X == x)
4997 explicit_bounds.X = stored_explicit_bounds.X;
4999 if (explicit_bounds.Y == y)
5000 explicit_bounds.Y = stored_explicit_bounds.Y;
5002 if (explicit_bounds.Width == width)
5003 explicit_bounds.Width = stored_explicit_bounds.Width;
5005 if (explicit_bounds.Height == height)
5006 explicit_bounds.Height = stored_explicit_bounds.Height;
5009 [EditorBrowsable(EditorBrowsableState.Advanced)]
5010 protected virtual void SetClientSizeCore(int x, int y) {
5011 Size NewSize = InternalSizeFromClientSize (new Size (x, y));
5013 if (NewSize != Size.Empty)
5014 SetBounds (bounds.X, bounds.Y, NewSize.Width, NewSize.Height, BoundsSpecified.Size);
5017 [EditorBrowsable(EditorBrowsableState.Advanced)]
5018 protected internal void SetStyle(ControlStyles flag, bool value) {
5020 control_style |= flag;
5022 control_style &= ~flag;
5026 protected void SetTopLevel(bool value) {
5027 if ((GetTopLevel() != value) && (parent != null)) {
5028 throw new ArgumentException ("Cannot change toplevel style of a parented control.");
5032 if (IsHandleCreated && value != Visible) {
5036 // XXX MS.NET causes handle to be created here
5037 if (!IsHandleCreated)
5040 is_toplevel = value;
5043 protected virtual void SetVisibleCore(bool value) {
5044 if (value != is_visible) {
5047 if (is_visible && ((window.Handle == IntPtr.Zero) || !is_created)) {
5049 if (!(this is Form))
5053 if (IsHandleCreated) {
5054 XplatUI.SetVisible (Handle, is_visible, true);
5056 if (parent != null && parent.IsHandleCreated) {
5057 parent.Invalidate (bounds);
5062 } else if (is_visible && this is Form) {
5063 // If we are Min or Max, we won't get a WM_SHOWWINDOW from SetWindowState,
5064 // so we need to manually create our children, and set them visible
5065 // (This normally happens in WmShowWindow.)
5066 if ((this as Form).WindowState != FormWindowState.Normal)
5067 OnVisibleChanged (EventArgs.Empty);
5069 // Explicitly move Toplevel windows to where we want them;
5070 // apparently moving unmapped toplevel windows doesn't work
5071 XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
5073 // If we are becoming visible, z-order may have changed while
5074 // we were invisible, so update our z-order position
5076 parent.UpdateZOrderOfChild (this);
5079 if (!(this is Form))
5080 OnVisibleChanged (EventArgs.Empty);
5083 OnVisibleChanged(EventArgs.Empty);
5088 [EditorBrowsable (EditorBrowsableState.Advanced)]
5094 virtual Size SizeFromClientSize (Size clientSize) {
5095 return InternalSizeFromClientSize (clientSize);
5098 [EditorBrowsable(EditorBrowsableState.Advanced)]
5099 protected void UpdateBounds() {
5100 if (!IsHandleCreated)
5110 XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
5112 UpdateBounds(x, y, width, height, client_width, client_height);
5115 [EditorBrowsable(EditorBrowsableState.Advanced)]
5116 protected void UpdateBounds(int x, int y, int width, int height) {
5120 // Calculate client rectangle
5121 rect = new Rectangle(0, 0, 0, 0);
5124 XplatUI.CalculateWindowRect(ref rect, cp, cp.menu, out rect);
5125 UpdateBounds(x, y, width, height, width - (rect.Right - rect.Left), height - (rect.Bottom - rect.Top));
5128 [EditorBrowsable(EditorBrowsableState.Advanced)]
5129 protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
5130 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
5132 bool resized = false;
5134 // Needed to generate required notifications
5135 if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
5139 if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
5146 bounds.Height=height;
5148 // Assume explicit bounds set. SetBoundsCore will restore old bounds
5150 explicit_bounds = bounds;
5152 client_size.Width=clientWidth;
5153 client_size.Height=clientHeight;
5156 OnLocationChanged(EventArgs.Empty);
5158 if (!background_color.IsEmpty && background_color.A < byte.MaxValue)
5163 OnSizeChanged(EventArgs.Empty);
5165 OnClientSizeChanged (EventArgs.Empty);
5170 [EditorBrowsable(EditorBrowsableState.Advanced)]
5171 protected void UpdateStyles() {
5172 if (!IsHandleCreated) {
5176 XplatUI.SetWindowStyle(window.Handle, CreateParams);
5177 OnStyleChanged(EventArgs.Empty);
5180 private void UpdateZOrderOfChild(Control child) {
5181 if (IsHandleCreated && child.IsHandleCreated && (child.parent == this) && Hwnd.ObjectFromHandle(child.Handle).Mapped) {
5182 // Need to take into account all controls
5183 Control [] all_controls = child_controls.GetAllControls ();
5185 int index = Array.IndexOf (all_controls, child);
5187 for (; index > 0; index--) {
5188 if (!all_controls [index - 1].IsHandleCreated || !all_controls [index - 1].VisibleInternal || !Hwnd.ObjectFromHandle(all_controls [index - 1].Handle).Mapped)
5194 XplatUI.SetZOrder(child.Handle, all_controls [index - 1].Handle, false, false);
5196 IntPtr after = AfterTopMostControl ();
5197 if (after != IntPtr.Zero && after != child.Handle)
5198 XplatUI.SetZOrder (child.Handle, after, false, false);
5200 XplatUI.SetZOrder (child.Handle, IntPtr.Zero, true, false);
5205 // Override this if there is a control that shall always remain on
5206 // top of other controls (such as scrollbars). If there are several
5207 // of these controls, the bottom-most should be returned.
5208 internal virtual IntPtr AfterTopMostControl () {
5212 // internal because we need to call it from ScrollableControl.OnVisibleChanged
5213 internal void UpdateChildrenZOrder() {
5214 Control [] controls;
5216 if (!IsHandleCreated) {
5220 // XXX This code is severely broken. It leaks
5221 // the "zero_sized" abstraction out of the X11
5222 // backend and into Control.cs. It'll work on
5223 // windows simply by virtue of windows never
5224 // setting that field to true.
5226 // basically what we need to guard against is
5227 // calling XplatUI.SetZOrder on an hwnd that
5228 // corresponds to an unmapped X window.
5229 controls = child_controls.GetAllControls ();
5231 ArrayList children_to_order = new ArrayList ();
5233 for (int i = 0; i < controls.Length; i ++) {
5234 if (!controls[i].IsHandleCreated || !controls[i].VisibleInternal)
5237 Hwnd hwnd = Hwnd.ObjectFromHandle (controls[i].Handle);
5238 if (hwnd.zero_sized)
5241 children_to_order.Add (controls[i]);
5244 for (int i = 1; i < children_to_order.Count; i ++) {
5245 Control upper = (Control)children_to_order[i-1];
5246 Control lower = (Control)children_to_order[i];
5248 XplatUI.SetZOrder(lower.Handle, upper.Handle, false, false);
5252 [EditorBrowsable(EditorBrowsableState.Advanced)]
5253 protected void UpdateZOrder() {
5254 if (parent != null) {
5255 parent.UpdateZOrderOfChild(this);
5259 protected virtual void WndProc(ref Message m) {
5261 Console.WriteLine("Control {0} received message {1}", window.Handle == IntPtr.Zero ? this.Text : XplatUI.Window(window.Handle), m.ToString ());
5263 if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
5267 switch((Msg)m.Msg) {
5268 case Msg.WM_DESTROY: {
5273 case Msg.WM_WINDOWPOSCHANGED: {
5274 WmWindowPosChanged(ref m);
5278 // Nice description of what should happen when handling WM_PAINT
5279 // can be found here: http://pluralsight.com/wiki/default.aspx/Craig/FlickerFreeControlDrawing.html
5280 // and here http://msdn.microsoft.com/msdnmag/issues/06/03/WindowsFormsPerformance/
5281 case Msg.WM_PAINT: {
5286 // The DefWndProc will never have to handle this, we always paint the background in managed code
5287 // In theory this code would look at ControlStyles.AllPaintingInWmPaint and and call OnPaintBackground
5288 // here but it just makes things more complicated...
5289 case Msg.WM_ERASEBKGND: {
5290 WmEraseBackground (ref m);
5294 case Msg.WM_LBUTTONUP: {
5295 WmLButtonUp (ref m);
5299 case Msg.WM_LBUTTONDOWN: {
5300 WmLButtonDown (ref m);
5304 case Msg.WM_LBUTTONDBLCLK: {
5305 WmLButtonDblClick (ref m);
5309 case Msg.WM_MBUTTONUP: {
5310 WmMButtonUp (ref m);
5314 case Msg.WM_MBUTTONDOWN: {
5315 WmMButtonDown (ref m);
5319 case Msg.WM_MBUTTONDBLCLK: {
5320 WmMButtonDblClick (ref m);
5324 case Msg.WM_RBUTTONUP: {
5325 WmRButtonUp (ref m);
5329 case Msg.WM_RBUTTONDOWN: {
5330 WmRButtonDown (ref m);
5334 case Msg.WM_RBUTTONDBLCLK: {
5335 WmRButtonDblClick (ref m);
5339 case Msg.WM_CONTEXTMENU: {
5340 WmContextMenu (ref m);
5344 case Msg.WM_MOUSEWHEEL: {
5345 WmMouseWheel (ref m);
5349 case Msg.WM_MOUSEMOVE: {
5350 WmMouseMove (ref m);
5354 case Msg.WM_SHOWWINDOW: {
5355 WmShowWindow (ref m);
5359 case Msg.WM_CREATE: {
5364 case Msg.WM_MOUSE_ENTER: {
5365 WmMouseEnter (ref m);
5369 case Msg.WM_MOUSELEAVE: {
5370 WmMouseLeave (ref m);
5374 case Msg.WM_MOUSEHOVER: {
5375 WmMouseHover (ref m);
5379 case Msg.WM_SYSKEYUP: {
5384 case Msg.WM_SYSKEYDOWN:
5385 case Msg.WM_KEYDOWN:
5387 case Msg.WM_SYSCHAR:
5398 case Msg.WM_KILLFOCUS: {
5399 WmKillFocus (ref m);
5403 case Msg.WM_SETFOCUS: {
5408 case Msg.WM_SYSCOLORCHANGE: {
5409 WmSysColorChange (ref m);
5413 case Msg.WM_SETCURSOR: {
5414 WmSetCursor (ref m);
5418 case Msg.WM_CAPTURECHANGED: {
5419 WmCaptureChanged (ref m);
5423 case Msg.WM_CHANGEUISTATE: {
5424 WmChangeUIState (ref m);
5428 case Msg.WM_UPDATEUISTATE: {
5429 WmUpdateUIState (ref m);
5439 #endregion // Public Instance Methods
5443 private void WmDestroy (ref Message m) {
5444 OnHandleDestroyed(EventArgs.Empty);
5446 IntPtr handle = window.Handle;
5448 window.InvalidateHandle();
5451 if (is_recreating) {
5453 Console.WriteLine ("Creating handle for {0:X}", handle.ToInt32());
5457 Console.WriteLine (" + new handle = {0:X}", Handle.ToInt32());
5459 is_recreating = false;
5463 is_disposing = false;
5468 private void WmWindowPosChanged (ref Message m) {
5470 Rectangle save_bounds = explicit_bounds;
5472 explicit_bounds = save_bounds;
5473 if (GetStyle(ControlStyles.ResizeRedraw)) {
5480 // Nice description of what should happen when handling WM_PAINT
5481 // can be found here: http://pluralsight.com/wiki/default.aspx/Craig/FlickerFreeControlDrawing.html
5482 // and here http://msdn.microsoft.com/msdnmag/issues/06/03/WindowsFormsPerformance/
5483 private void WmPaint (ref Message m) {
5484 PaintEventArgs paint_event;
5486 IntPtr handle = Handle;
5488 paint_event = XplatUI.PaintEventStart (ref m, handle, true);
5490 if (paint_event == null)
5493 DoubleBuffer current_buffer = null;
5494 if (UseDoubleBuffering) {
5495 current_buffer = GetBackBuffer ();
5496 // This optimization doesn't work when the area is invalidated
5497 // during a paint operation because finishing the paint operation
5498 // clears the invalidated region and then this thing keeps the new
5499 // invalidate from working. To re-enable this, we would need a
5500 // mechanism to allow for nested invalidates (see bug #328681)
5501 //if (!current_buffer.InvalidRegion.IsVisible (paint_event.ClipRectangle)) {
5502 // // Just blit the previous image
5503 // current_buffer.Blit (paint_event);
5504 // XplatUI.PaintEventEnd (ref m, handle, true);
5507 current_buffer.Start (paint_event);
5510 if (!GetStyle(ControlStyles.Opaque)) {
5511 OnPaintBackground (paint_event);
5514 // Button-derived controls choose to ignore their Opaque style, give them a chance to draw their background anyways
5515 OnPaintBackgroundInternal (paint_event);
5517 OnPaintInternal(paint_event);
5518 if (!paint_event.Handled) {
5519 OnPaint (paint_event);
5522 if (current_buffer != null) {
5523 current_buffer.End (paint_event);
5527 XplatUI.PaintEventEnd (ref m, handle, true);
5530 private void WmEraseBackground (ref Message m) {
5531 // The DefWndProc will never have to handle this, we always paint the background in managed code
5532 // In theory this code would look at ControlStyles.AllPaintingInWmPaint and and call OnPaintBackground
5533 // here but it just makes things more complicated...
5534 m.Result = (IntPtr)1;
5537 private void WmLButtonUp (ref Message m)
5540 if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
5541 ProcessActiveTracker (ref m);
5547 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
5549 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
5552 HandleClick(mouse_clicks, me);
5555 if (InternalCapture) {
5556 InternalCapture = false;
5559 if (mouse_clicks > 1) {
5564 private void WmLButtonDown (ref Message m)
5567 if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
5568 ProcessActiveTracker (ref m);
5572 ValidationFailed = false;
5574 Select (true, true);
5576 if (!ValidationFailed) {
5577 InternalCapture = true;
5578 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
5579 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
5584 private void WmLButtonDblClick (ref Message m) {
5585 InternalCapture = true;
5587 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
5588 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
5592 private void WmMButtonUp (ref Message m) {
5595 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
5597 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
5600 HandleClick(mouse_clicks, me);
5602 if (InternalCapture) {
5603 InternalCapture = false;
5605 if (mouse_clicks > 1) {
5610 private void WmMButtonDown (ref Message m) {
5611 InternalCapture = true;
5612 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
5613 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
5617 private void WmMButtonDblClick (ref Message m) {
5618 InternalCapture = true;
5620 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
5621 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
5625 private void WmRButtonUp (ref Message m)
5628 if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
5629 ProcessActiveTracker (ref m);
5636 pt = new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()));
5637 pt = PointToScreen(pt);
5639 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
5641 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
5644 HandleClick(mouse_clicks, me);
5646 XplatUI.SendMessage(m.HWnd, Msg.WM_CONTEXTMENU, m.HWnd, (IntPtr)(pt.X + (pt.Y << 16)));
5649 if (InternalCapture) {
5650 InternalCapture = false;
5653 if (mouse_clicks > 1) {
5658 private void WmRButtonDown (ref Message m)
5661 if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
5662 ProcessActiveTracker (ref m);
5666 InternalCapture = true;
5667 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
5668 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
5672 private void WmRButtonDblClick (ref Message m) {
5673 InternalCapture = true;
5675 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
5676 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
5680 private void WmContextMenu (ref Message m) {
5681 if (context_menu != null) {
5684 pt = new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()));
5686 if (pt.X == -1 || pt.Y == -1) {
5687 pt.X = (this.Width / 2) + this.Left;
5688 pt.Y = (this.Height / 2) + this.Top;
5689 pt = this.PointToScreen (pt);
5692 context_menu.Show (this, PointToClient (pt));
5697 // If there isn't a regular context menu, show the Strip version
5698 if (context_menu == null && context_menu_strip != null) {
5701 pt = new Point (LowOrder ((int)m.LParam.ToInt32 ()), HighOrder ((int)m.LParam.ToInt32 ()));
5703 if (pt.X == -1 || pt.Y == -1) {
5704 pt.X = (this.Width / 2) + this.Left;
5705 pt.Y = (this.Height /2) + this.Top;
5706 pt = this.PointToScreen (pt);
5709 context_menu_strip.Show (this, PointToClient (pt));
5716 private void WmCreate (ref Message m) {
5717 OnHandleCreated(EventArgs.Empty);
5720 private void WmMouseWheel (ref Message m) {
5722 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((long) m.WParam),
5723 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
5724 HighOrder((long)m.WParam)));
5728 private void WmMouseMove (ref Message m) {
5729 if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
5730 MouseEventArgs args = new MouseEventArgs (
5731 FromParamToMouseButtons ((int)m.WParam.ToInt32 ()),
5733 Control.MousePosition.X,
5734 Control.MousePosition.Y,
5737 active_tracker.OnMotion (args);
5741 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
5743 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
5747 private void WmMouseEnter (ref Message m) {
5752 OnMouseEnter(EventArgs.Empty);
5755 private void WmMouseLeave (ref Message m) {
5757 OnMouseLeave(EventArgs.Empty);
5760 private void WmMouseHover (ref Message m) {
5761 OnMouseHover(EventArgs.Empty);
5764 private void WmShowWindow (ref Message m) {
5768 Form frm = this as Form;
5769 if (m.WParam.ToInt32() != 0) {
5770 if (m.LParam.ToInt32 () == 0) {
5773 // Make sure all our children are properly parented to us
5774 Control [] controls = child_controls.GetAllControls ();
5775 bool parented = false;
5776 for (int i=0; i<controls.Length; i++) {
5777 if (controls [i].is_visible && controls[i].IsHandleCreated)
5778 if (XplatUI.GetParent (controls[i].Handle) != window.Handle) {
5779 XplatUI.SetParent(controls[i].Handle, window.Handle);
5786 UpdateChildrenZOrder ();
5789 if (parent != null && Focused) {
5791 // Need to start at parent, GetContainerControl might return ourselves if we're a container
5792 container = (Control)parent.GetContainerControl();
5793 if (container != null && (frm == null || !frm.IsMdiChild)) {
5794 container.SelectNextControl(this, true, true, true, true);
5800 frm.waiting_showwindow = false;
5802 // If the form is Max/Min, it got its OnVisibleChanged in SetVisibleCore
5804 if (!IsRecreating && (frm.IsMdiChild || frm.WindowState == FormWindowState.Normal)) /* XXX make sure this works for mdi forms */
5805 OnVisibleChanged(EventArgs.Empty);
5806 } else if (is_toplevel)
5807 OnVisibleChanged(EventArgs.Empty);
5810 private void WmSysKeyUp (ref Message m) {
5811 if (ProcessKeyMessage(ref m)) {
5812 m.Result = IntPtr.Zero;
5816 if ((m.WParam.ToInt32() & (int)Keys.KeyCode) == (int)Keys.Menu) {
5820 if (form != null && form.ActiveMenu != null) {
5821 form.ActiveMenu.ProcessCmdKey(ref m, (Keys)m.WParam.ToInt32());
5825 if (ToolStripManager.ProcessMenuKey (ref m))
5833 private void WmKeys (ref Message m)
5835 if (ProcessKeyMessage(ref m)) {
5836 m.Result = IntPtr.Zero;
5842 private void WmHelp (ref Message m) {
5844 if (m.LParam != IntPtr.Zero) {
5847 hi = new HELPINFO();
5849 hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
5850 mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
5852 mouse_pos = Control.MousePosition;
5854 OnHelpRequested(new HelpEventArgs(mouse_pos));
5855 m.Result = (IntPtr)1;
5858 private void WmKillFocus (ref Message m) {
5859 this.has_focus = false;
5860 OnLostFocus (EventArgs.Empty);
5863 private void WmSetFocus (ref Message m) {
5865 this.has_focus = true;
5866 OnGotFocus (EventArgs.Empty);
5870 private void WmSysColorChange (ref Message m) {
5871 ThemeEngine.Current.ResetDefaults();
5872 OnSystemColorsChanged(EventArgs.Empty);
5875 private void WmSetCursor (ref Message m) {
5876 if ((cursor == null && use_wait_cursor == false) || ((HitTest)(m.LParam.ToInt32() & 0xffff) != HitTest.HTCLIENT)) {
5881 XplatUI.SetCursor(window.Handle, Cursor.handle);
5882 m.Result = (IntPtr)1;
5885 private void WmCaptureChanged (ref Message m) {
5886 is_captured = false;
5887 OnMouseCaptureChanged (EventArgs.Empty);
5888 m.Result = (IntPtr) 0;
5891 private void WmChangeUIState (ref Message m) {
5892 foreach (Control control in Controls) {
5893 XplatUI.SendMessage (control.Handle, Msg.WM_UPDATEUISTATE, m.WParam, m.LParam);
5897 private void WmUpdateUIState (ref Message m) {
5898 int action = LowOrder (m.WParam.ToInt32 ());
5899 int element = HighOrder (m.WParam.ToInt32 ());
5901 if (action == (int) MsgUIState.UIS_INITIALIZE)
5904 UICues cues = UICues.None;
5906 if ((element & (int) MsgUIState.UISF_HIDEACCEL) != 0) {
5907 if ((action == (int) MsgUIState.UIS_CLEAR) != show_keyboard_cues) {
5908 cues |= UICues.ChangeKeyboard;
5909 show_keyboard_cues = (action == (int) MsgUIState.UIS_CLEAR);
5913 if ((element & (int) MsgUIState.UISF_HIDEFOCUS) != 0) {
5914 if ((action == (int) MsgUIState.UIS_CLEAR) != show_focus_cues) {
5915 cues |= UICues.ChangeFocus;
5916 show_focus_cues = (action == (int) MsgUIState.UIS_CLEAR);
5920 if ((cues & UICues.Changed) != UICues.None) {
5921 OnChangeUICues (new UICuesEventArgs (cues));
5928 #region OnXXX methods
5930 protected virtual void OnAutoSizeChanged (EventArgs e)
5932 EventHandler eh = (EventHandler)(Events[AutoSizeChangedEvent]);
5938 [EditorBrowsable (EditorBrowsableState.Advanced)]
5939 protected virtual void OnBackColorChanged(EventArgs e) {
5940 EventHandler eh = (EventHandler)(Events [BackColorChangedEvent]);
5943 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
5946 [EditorBrowsable(EditorBrowsableState.Advanced)]
5947 protected virtual void OnBackgroundImageChanged(EventArgs e) {
5948 EventHandler eh = (EventHandler)(Events [BackgroundImageChangedEvent]);
5951 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
5955 [EditorBrowsable (EditorBrowsableState.Advanced)]
5956 protected virtual void OnBackgroundImageLayoutChanged (EventArgs e)
5958 EventHandler eh = (EventHandler)(Events[BackgroundImageLayoutChangedEvent]);
5964 [EditorBrowsable(EditorBrowsableState.Advanced)]
5965 protected virtual void OnBindingContextChanged(EventArgs e) {
5966 CheckDataBindings ();
5967 EventHandler eh = (EventHandler)(Events [BindingContextChangedEvent]);
5970 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
5973 [EditorBrowsable(EditorBrowsableState.Advanced)]
5974 protected virtual void OnCausesValidationChanged(EventArgs e) {
5975 EventHandler eh = (EventHandler)(Events [CausesValidationChangedEvent]);
5980 [EditorBrowsable(EditorBrowsableState.Advanced)]
5981 protected virtual void OnChangeUICues(UICuesEventArgs e) {
5982 UICuesEventHandler eh = (UICuesEventHandler)(Events [ChangeUICuesEvent]);
5987 [EditorBrowsable(EditorBrowsableState.Advanced)]
5988 protected virtual void OnClick(EventArgs e) {
5989 EventHandler eh = (EventHandler)(Events [ClickEvent]);
5995 [EditorBrowsable (EditorBrowsableState.Advanced)]
5996 protected virtual void OnClientSizeChanged (EventArgs e)
5998 EventHandler eh = (EventHandler)(Events[ClientSizeChangedEvent]);
6004 [EditorBrowsable(EditorBrowsableState.Advanced)]
6005 protected virtual void OnContextMenuChanged(EventArgs e) {
6006 EventHandler eh = (EventHandler)(Events [ContextMenuChangedEvent]);
6012 [EditorBrowsable (EditorBrowsableState.Advanced)]
6013 protected virtual void OnContextMenuStripChanged (EventArgs e) {
6014 EventHandler eh = (EventHandler)(Events [ContextMenuStripChangedEvent]);
6020 [EditorBrowsable(EditorBrowsableState.Advanced)]
6021 protected virtual void OnControlAdded(ControlEventArgs e) {
6022 ControlEventHandler eh = (ControlEventHandler)(Events [ControlAddedEvent]);
6027 [EditorBrowsable(EditorBrowsableState.Advanced)]
6028 protected virtual void OnControlRemoved(ControlEventArgs e) {
6029 ControlEventHandler eh = (ControlEventHandler)(Events [ControlRemovedEvent]);
6034 [EditorBrowsable(EditorBrowsableState.Advanced)]
6035 protected virtual void OnCreateControl() {
6039 [EditorBrowsable(EditorBrowsableState.Advanced)]
6040 protected virtual void OnCursorChanged(EventArgs e) {
6041 EventHandler eh = (EventHandler)(Events [CursorChangedEvent]);
6046 for (int i = 0; i < child_controls.Count; i++) child_controls[i].OnParentCursorChanged (e);
6050 [EditorBrowsable(EditorBrowsableState.Advanced)]
6051 protected virtual void OnDockChanged(EventArgs e) {
6052 EventHandler eh = (EventHandler)(Events [DockChangedEvent]);
6057 [EditorBrowsable(EditorBrowsableState.Advanced)]
6058 protected virtual void OnDoubleClick(EventArgs e) {
6059 EventHandler eh = (EventHandler)(Events [DoubleClickEvent]);
6064 [EditorBrowsable(EditorBrowsableState.Advanced)]
6065 protected virtual void OnDragDrop(DragEventArgs drgevent) {
6066 DragEventHandler eh = (DragEventHandler)(Events [DragDropEvent]);
6068 eh (this, drgevent);
6071 [EditorBrowsable(EditorBrowsableState.Advanced)]
6072 protected virtual void OnDragEnter(DragEventArgs drgevent) {
6073 DragEventHandler eh = (DragEventHandler)(Events [DragEnterEvent]);
6075 eh (this, drgevent);
6078 [EditorBrowsable(EditorBrowsableState.Advanced)]
6079 protected virtual void OnDragLeave(EventArgs e) {
6080 EventHandler eh = (EventHandler)(Events [DragLeaveEvent]);
6085 [EditorBrowsable(EditorBrowsableState.Advanced)]
6086 protected virtual void OnDragOver(DragEventArgs drgevent) {
6087 DragEventHandler eh = (DragEventHandler)(Events [DragOverEvent]);
6089 eh (this, drgevent);
6092 [EditorBrowsable(EditorBrowsableState.Advanced)]
6093 protected virtual void OnEnabledChanged(EventArgs e) {
6094 if (IsHandleCreated) {
6096 if (((Form)this).context == null) {
6097 XplatUI.EnableWindow(window.Handle, Enabled);
6100 XplatUI.EnableWindow(window.Handle, Enabled);
6105 EventHandler eh = (EventHandler)(Events [EnabledChangedEvent]);
6109 for (int i=0; i<child_controls.Count; i++) {
6110 child_controls[i].OnParentEnabledChanged(e);
6114 [EditorBrowsable(EditorBrowsableState.Advanced)]
6115 protected virtual void OnEnter(EventArgs e) {
6116 EventHandler eh = (EventHandler)(Events [EnterEvent]);
6121 [EditorBrowsable(EditorBrowsableState.Advanced)]
6122 protected virtual void OnFontChanged(EventArgs e) {
6123 EventHandler eh = (EventHandler)(Events [FontChangedEvent]);
6126 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
6129 [EditorBrowsable(EditorBrowsableState.Advanced)]
6130 protected virtual void OnForeColorChanged(EventArgs e) {
6131 EventHandler eh = (EventHandler)(Events [ForeColorChangedEvent]);
6134 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
6137 [EditorBrowsable(EditorBrowsableState.Advanced)]
6138 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
6139 GiveFeedbackEventHandler eh = (GiveFeedbackEventHandler)(Events [GiveFeedbackEvent]);
6141 eh (this, gfbevent);
6144 [EditorBrowsable(EditorBrowsableState.Advanced)]
6145 protected virtual void OnGotFocus(EventArgs e) {
6146 EventHandler eh = (EventHandler)(Events [GotFocusEvent]);
6151 [EditorBrowsable(EditorBrowsableState.Advanced)]
6152 protected virtual void OnHandleCreated(EventArgs e) {
6153 EventHandler eh = (EventHandler)(Events [HandleCreatedEvent]);
6158 [EditorBrowsable(EditorBrowsableState.Advanced)]
6159 protected virtual void OnHandleDestroyed(EventArgs e) {
6160 EventHandler eh = (EventHandler)(Events [HandleDestroyedEvent]);
6165 internal void RaiseHelpRequested (HelpEventArgs hevent) {
6166 OnHelpRequested (hevent);
6169 [EditorBrowsable(EditorBrowsableState.Advanced)]
6170 protected virtual void OnHelpRequested(HelpEventArgs hevent) {
6171 HelpEventHandler eh = (HelpEventHandler)(Events [HelpRequestedEvent]);
6176 protected virtual void OnImeModeChanged(EventArgs e) {
6177 EventHandler eh = (EventHandler)(Events [ImeModeChangedEvent]);
6182 [EditorBrowsable(EditorBrowsableState.Advanced)]
6183 protected virtual void OnInvalidated(InvalidateEventArgs e) {
6184 if (UseDoubleBuffering) {
6185 // should this block be here? seems like it
6186 // would be more at home in
6187 // NotifyInvalidated..
6188 if (e.InvalidRect == ClientRectangle) {
6189 InvalidateBackBuffer ();
6190 } else if (backbuffer != null){
6191 // we need this Inflate call here so
6192 // that the border of the rectangle is
6193 // considered Visible (the
6194 // invalid_region.IsVisible call) in
6195 // the WM_PAINT handling below.
6196 Rectangle r = Rectangle.Inflate(e.InvalidRect, 1,1);
6197 backbuffer.InvalidRegion.Union (r);
6201 InvalidateEventHandler eh = (InvalidateEventHandler)(Events [InvalidatedEvent]);
6206 [EditorBrowsable(EditorBrowsableState.Advanced)]
6207 protected virtual void OnKeyDown(KeyEventArgs e) {
6208 KeyEventHandler eh = (KeyEventHandler)(Events [KeyDownEvent]);
6213 [EditorBrowsable(EditorBrowsableState.Advanced)]
6214 protected virtual void OnKeyPress(KeyPressEventArgs e) {
6215 KeyPressEventHandler eh = (KeyPressEventHandler)(Events [KeyPressEvent]);
6220 [EditorBrowsable(EditorBrowsableState.Advanced)]
6221 protected virtual void OnKeyUp(KeyEventArgs e) {
6222 KeyEventHandler eh = (KeyEventHandler)(Events [KeyUpEvent]);
6227 [EditorBrowsable(EditorBrowsableState.Advanced)]
6228 protected virtual void OnLayout(LayoutEventArgs levent) {
6229 LayoutEventHandler eh = (LayoutEventHandler)(Events [LayoutEvent]);
6236 // If our layout changed our PreferredSize, our parent
6237 // needs to re-lay us out. However, it's not always possible to
6238 // be our preferred size, so only try once so we don't loop forever.
6239 if (Parent != null && AutoSize && !nested_layout && PreferredSize != s) {
6240 nested_layout = true;
6241 Parent.PerformLayout ();
6242 nested_layout = false;
6246 LayoutEngine.Layout (this, levent);
6249 [EditorBrowsable(EditorBrowsableState.Advanced)]
6250 protected virtual void OnLeave(EventArgs e) {
6251 EventHandler eh = (EventHandler)(Events [LeaveEvent]);
6256 [EditorBrowsable(EditorBrowsableState.Advanced)]
6257 protected virtual void OnLocationChanged(EventArgs e) {
6259 EventHandler eh = (EventHandler)(Events [LocationChangedEvent]);
6264 [EditorBrowsable(EditorBrowsableState.Advanced)]
6265 protected virtual void OnLostFocus(EventArgs e) {
6266 EventHandler eh = (EventHandler)(Events [LostFocusEvent]);
6272 protected virtual void OnMarginChanged (EventArgs e)
6274 EventHandler eh = (EventHandler)(Events[MarginChangedEvent]);
6279 [EditorBrowsable (EditorBrowsableState.Advanced)]
6281 protected virtual void OnMouseCaptureChanged (EventArgs e)
6283 internal virtual void OnMouseCaptureChanged (EventArgs e)
6286 EventHandler eh = (EventHandler)(Events [MouseCaptureChangedEvent]);
6292 [EditorBrowsable (EditorBrowsableState.Advanced)]
6293 protected virtual void OnMouseClick (MouseEventArgs e)
6295 MouseEventHandler eh = (MouseEventHandler)(Events [MouseClickEvent]);
6300 [EditorBrowsable (EditorBrowsableState.Advanced)]
6301 protected virtual void OnMouseDoubleClick (MouseEventArgs e)
6303 MouseEventHandler eh = (MouseEventHandler)(Events [MouseDoubleClickEvent]);
6309 [EditorBrowsable(EditorBrowsableState.Advanced)]
6310 protected virtual void OnMouseDown(MouseEventArgs e) {
6311 MouseEventHandler eh = (MouseEventHandler)(Events [MouseDownEvent]);
6316 [EditorBrowsable(EditorBrowsableState.Advanced)]
6317 protected virtual void OnMouseEnter(EventArgs e) {
6318 EventHandler eh = (EventHandler)(Events [MouseEnterEvent]);
6323 [EditorBrowsable(EditorBrowsableState.Advanced)]
6324 protected virtual void OnMouseHover(EventArgs e) {
6325 EventHandler eh = (EventHandler)(Events [MouseHoverEvent]);
6330 [EditorBrowsable(EditorBrowsableState.Advanced)]
6331 protected virtual void OnMouseLeave(EventArgs e) {
6332 EventHandler eh = (EventHandler)(Events [MouseLeaveEvent]);
6337 [EditorBrowsable(EditorBrowsableState.Advanced)]
6338 protected virtual void OnMouseMove(MouseEventArgs e) {
6339 MouseEventHandler eh = (MouseEventHandler)(Events [MouseMoveEvent]);
6344 [EditorBrowsable(EditorBrowsableState.Advanced)]
6345 protected virtual void OnMouseUp(MouseEventArgs e) {
6346 MouseEventHandler eh = (MouseEventHandler)(Events [MouseUpEvent]);
6351 [EditorBrowsable(EditorBrowsableState.Advanced)]
6352 protected virtual void OnMouseWheel(MouseEventArgs e) {
6353 MouseEventHandler eh = (MouseEventHandler)(Events [MouseWheelEvent]);
6358 [EditorBrowsable(EditorBrowsableState.Advanced)]
6359 protected virtual void OnMove(EventArgs e) {
6360 EventHandler eh = (EventHandler)(Events [MoveEvent]);
6365 [EditorBrowsable(EditorBrowsableState.Advanced)]
6366 protected virtual void OnNotifyMessage(Message m) {
6371 protected virtual void OnPaddingChanged (EventArgs e) {
6372 EventHandler eh = (EventHandler) (Events [PaddingChangedEvent]);
6378 [EditorBrowsable(EditorBrowsableState.Advanced)]
6379 protected virtual void OnPaint(PaintEventArgs e) {
6380 PaintEventHandler eh = (PaintEventHandler)(Events [PaintEvent]);
6385 internal virtual void OnPaintBackgroundInternal(PaintEventArgs e) {
6389 internal virtual void OnPaintInternal(PaintEventArgs e) {
6393 [EditorBrowsable(EditorBrowsableState.Advanced)]
6394 protected virtual void OnPaintBackground(PaintEventArgs pevent) {
6395 PaintControlBackground (pevent);
6398 [EditorBrowsable(EditorBrowsableState.Advanced)]
6399 protected virtual void OnParentBackColorChanged(EventArgs e) {
6400 if (background_color.IsEmpty && background_image==null) {
6402 OnBackColorChanged(e);
6406 [EditorBrowsable(EditorBrowsableState.Advanced)]
6407 protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
6409 OnBackgroundImageChanged(e);
6412 [EditorBrowsable(EditorBrowsableState.Advanced)]
6413 protected virtual void OnParentBindingContextChanged(EventArgs e) {
6414 if (binding_context==null && Parent != null) {
6415 binding_context=Parent.binding_context;
6416 OnBindingContextChanged(e);
6420 [EditorBrowsable(EditorBrowsableState.Advanced)]
6421 protected virtual void OnParentChanged(EventArgs e) {
6422 EventHandler eh = (EventHandler)(Events [ParentChangedEvent]);
6428 [EditorBrowsable (EditorBrowsableState.Advanced)]
6429 protected virtual void OnParentCursorChanged (EventArgs e)
6434 [EditorBrowsable (EditorBrowsableState.Advanced)]
6435 protected virtual void OnParentEnabledChanged(EventArgs e) {
6437 OnEnabledChanged(e);
6441 [EditorBrowsable(EditorBrowsableState.Advanced)]
6442 protected virtual void OnParentFontChanged(EventArgs e) {
6449 [EditorBrowsable(EditorBrowsableState.Advanced)]
6450 protected virtual void OnParentForeColorChanged(EventArgs e) {
6451 if (foreground_color.IsEmpty) {
6453 OnForeColorChanged(e);
6457 [EditorBrowsable(EditorBrowsableState.Advanced)]
6458 protected virtual void OnParentRightToLeftChanged(EventArgs e) {
6459 if (right_to_left==RightToLeft.Inherit) {
6461 OnRightToLeftChanged(e);
6465 [EditorBrowsable(EditorBrowsableState.Advanced)]
6466 protected virtual void OnParentVisibleChanged(EventArgs e) {
6468 OnVisibleChanged(e);
6472 [EditorBrowsable(EditorBrowsableState.Advanced)]
6473 protected virtual void OnQueryContinueDrag (QueryContinueDragEventArgs qcdevent)
6475 QueryContinueDragEventHandler eh = (QueryContinueDragEventHandler)(Events [QueryContinueDragEvent]);
6477 eh (this, qcdevent);
6481 [EditorBrowsable (EditorBrowsableState.Advanced)]
6482 protected virtual void OnPreviewKeyDown (PreviewKeyDownEventArgs e)
6484 PreviewKeyDownEventHandler eh = (PreviewKeyDownEventHandler)(Events[PreviewKeyDownEvent]);
6489 [EditorBrowsable (EditorBrowsableState.Advanced)]
6490 protected virtual void OnPrint (PaintEventArgs e)
6492 PaintEventHandler eh = (PaintEventHandler)(Events[PaintEvent]);
6497 [EditorBrowsable (EditorBrowsableState.Advanced)]
6498 protected virtual void OnRegionChanged (EventArgs e)
6500 EventHandler eh = (EventHandler)(Events[RegionChangedEvent]);
6506 [EditorBrowsable(EditorBrowsableState.Advanced)]
6507 protected virtual void OnResize(EventArgs e) {
6508 OnResizeInternal (e);
6511 internal virtual void OnResizeInternal (EventArgs e) {
6512 PerformLayout(this, "Bounds");
6514 EventHandler eh = (EventHandler)(Events [ResizeEvent]);
6519 [EditorBrowsable(EditorBrowsableState.Advanced)]
6520 protected virtual void OnRightToLeftChanged(EventArgs e) {
6521 EventHandler eh = (EventHandler)(Events [RightToLeftChangedEvent]);
6524 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
6527 [EditorBrowsable(EditorBrowsableState.Advanced)]
6528 protected virtual void OnSizeChanged(EventArgs e) {
6529 DisposeBackBuffer ();
6531 EventHandler eh = (EventHandler)(Events [SizeChangedEvent]);
6536 [EditorBrowsable(EditorBrowsableState.Advanced)]
6537 protected virtual void OnStyleChanged(EventArgs e) {
6538 EventHandler eh = (EventHandler)(Events [StyleChangedEvent]);
6543 [EditorBrowsable(EditorBrowsableState.Advanced)]
6544 protected virtual void OnSystemColorsChanged(EventArgs e) {
6545 EventHandler eh = (EventHandler)(Events [SystemColorsChangedEvent]);
6550 [EditorBrowsable(EditorBrowsableState.Advanced)]
6551 protected virtual void OnTabIndexChanged(EventArgs e) {
6552 EventHandler eh = (EventHandler)(Events [TabIndexChangedEvent]);
6557 [EditorBrowsable(EditorBrowsableState.Advanced)]
6558 protected virtual void OnTabStopChanged(EventArgs e) {
6559 EventHandler eh = (EventHandler)(Events [TabStopChangedEvent]);
6564 [EditorBrowsable(EditorBrowsableState.Advanced)]
6565 protected virtual void OnTextChanged(EventArgs e) {
6566 EventHandler eh = (EventHandler)(Events [TextChangedEvent]);
6571 [EditorBrowsable(EditorBrowsableState.Advanced)]
6572 protected virtual void OnValidated(EventArgs e) {
6573 EventHandler eh = (EventHandler)(Events [ValidatedEvent]);
6578 [EditorBrowsable(EditorBrowsableState.Advanced)]
6579 protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
6580 CancelEventHandler eh = (CancelEventHandler)(Events [ValidatingEvent]);
6585 [EditorBrowsable(EditorBrowsableState.Advanced)]
6586 protected virtual void OnVisibleChanged(EventArgs e) {
6590 EventHandler eh = (EventHandler)(Events [VisibleChangedEvent]);
6594 // We need to tell our kids (including implicit ones)
6595 foreach (Control c in Controls.GetAllControls ())
6597 c.OnParentVisibleChanged (e);
6599 #endregion // OnXXX methods
6603 static object AutoSizeChangedEvent = new object ();
6605 static object BackColorChangedEvent = new object ();
6606 static object BackgroundImageChangedEvent = new object ();
6608 static object BackgroundImageLayoutChangedEvent = new object ();
6610 static object BindingContextChangedEvent = new object ();
6611 static object CausesValidationChangedEvent = new object ();
6612 static object ChangeUICuesEvent = new object ();
6613 static object ClickEvent = new object ();
6615 static object ClientSizeChangedEvent = new object ();
6617 static object ContextMenuChangedEvent = new object ();
6619 static object ContextMenuStripChangedEvent = new object ();
6621 static object ControlAddedEvent = new object ();
6622 static object ControlRemovedEvent = new object ();
6623 static object CursorChangedEvent = new object ();
6624 static object DockChangedEvent = new object ();
6625 static object DoubleClickEvent = new object ();
6626 static object DragDropEvent = new object ();
6627 static object DragEnterEvent = new object ();
6628 static object DragLeaveEvent = new object ();
6629 static object DragOverEvent = new object ();
6630 static object EnabledChangedEvent = new object ();
6631 static object EnterEvent = new object ();
6632 static object FontChangedEvent = new object ();
6633 static object ForeColorChangedEvent = new object ();
6634 static object GiveFeedbackEvent = new object ();
6635 static object GotFocusEvent = new object ();
6636 static object HandleCreatedEvent = new object ();
6637 static object HandleDestroyedEvent = new object ();
6638 static object HelpRequestedEvent = new object ();
6639 static object ImeModeChangedEvent = new object ();
6640 static object InvalidatedEvent = new object ();
6641 static object KeyDownEvent = new object ();
6642 static object KeyPressEvent = new object ();
6643 static object KeyUpEvent = new object ();
6644 static object LayoutEvent = new object ();
6645 static object LeaveEvent = new object ();
6646 static object LocationChangedEvent = new object ();
6647 static object LostFocusEvent = new object ();
6649 static object MarginChangedEvent = new object ();
6651 static object MouseCaptureChangedEvent = new object ();
6653 static object MouseClickEvent = new object ();
6654 static object MouseDoubleClickEvent = new object ();
6656 static object MouseDownEvent = new object ();
6657 static object MouseEnterEvent = new object ();
6658 static object MouseHoverEvent = new object ();
6659 static object MouseLeaveEvent = new object ();
6660 static object MouseMoveEvent = new object ();
6661 static object MouseUpEvent = new object ();
6662 static object MouseWheelEvent = new object ();
6663 static object MoveEvent = new object ();
6665 static object PaddingChangedEvent = new object ();
6667 static object PaintEvent = new object ();
6668 static object ParentChangedEvent = new object ();
6670 static object PreviewKeyDownEvent = new object ();
6672 static object QueryAccessibilityHelpEvent = new object ();
6673 static object QueryContinueDragEvent = new object ();
6675 static object RegionChangedEvent = new object ();
6677 static object ResizeEvent = new object ();
6678 static object RightToLeftChangedEvent = new object ();
6679 static object SizeChangedEvent = new object ();
6680 static object StyleChangedEvent = new object ();
6681 static object SystemColorsChangedEvent = new object ();
6682 static object TabIndexChangedEvent = new object ();
6683 static object TabStopChangedEvent = new object ();
6684 static object TextChangedEvent = new object ();
6685 static object ValidatedEvent = new object ();
6686 static object ValidatingEvent = new object ();
6687 static object VisibleChangedEvent = new object ();
6691 [EditorBrowsable (EditorBrowsableState.Never)]
6692 public event EventHandler AutoSizeChanged {
6693 add { Events.AddHandler (AutoSizeChangedEvent, value);}
6694 remove {Events.RemoveHandler (AutoSizeChangedEvent, value);}
6697 public event EventHandler BackColorChanged {
6698 add { Events.AddHandler (BackColorChangedEvent, value); }
6699 remove { Events.RemoveHandler (BackColorChangedEvent, value); }
6702 public event EventHandler BackgroundImageChanged {
6703 add { Events.AddHandler (BackgroundImageChangedEvent, value); }
6704 remove { Events.RemoveHandler (BackgroundImageChangedEvent, value); }
6708 public event EventHandler BackgroundImageLayoutChanged {
6709 add {Events.AddHandler (BackgroundImageLayoutChangedEvent, value);}
6710 remove {Events.RemoveHandler (BackgroundImageLayoutChangedEvent, value);}
6714 public event EventHandler BindingContextChanged {
6715 add { Events.AddHandler (BindingContextChangedEvent, value); }
6716 remove { Events.RemoveHandler (BindingContextChangedEvent, value); }
6719 public event EventHandler CausesValidationChanged {
6720 add { Events.AddHandler (CausesValidationChangedEvent, value); }
6721 remove { Events.RemoveHandler (CausesValidationChangedEvent, value); }
6724 public event UICuesEventHandler ChangeUICues {
6725 add { Events.AddHandler (ChangeUICuesEvent, value); }
6726 remove { Events.RemoveHandler (ChangeUICuesEvent, value); }
6729 public event EventHandler Click {
6730 add { Events.AddHandler (ClickEvent, value); }
6731 remove { Events.RemoveHandler (ClickEvent, value); }
6735 public event EventHandler ClientSizeChanged {
6736 add {Events.AddHandler (ClientSizeChangedEvent, value);}
6737 remove {Events.RemoveHandler (ClientSizeChangedEvent, value);}
6744 public event EventHandler ContextMenuChanged {
6745 add { Events.AddHandler (ContextMenuChangedEvent, value); }
6746 remove { Events.RemoveHandler (ContextMenuChangedEvent, value); }
6750 public event EventHandler ContextMenuStripChanged {
6751 add { Events.AddHandler (ContextMenuStripChangedEvent, value); }
6752 remove { Events.RemoveHandler (ContextMenuStripChangedEvent, value);}
6757 [EditorBrowsable(EditorBrowsableState.Advanced)]
6763 public event ControlEventHandler ControlAdded {
6764 add { Events.AddHandler (ControlAddedEvent, value); }
6765 remove { Events.RemoveHandler (ControlAddedEvent, value); }
6768 [EditorBrowsable(EditorBrowsableState.Advanced)]
6774 public event ControlEventHandler ControlRemoved {
6775 add { Events.AddHandler (ControlRemovedEvent, value); }
6776 remove { Events.RemoveHandler (ControlRemovedEvent, value); }
6779 [MWFDescription("Fired when the cursor for the control has been changed"), MWFCategory("PropertyChanged")]
6780 public event EventHandler CursorChanged {
6781 add { Events.AddHandler (CursorChangedEvent, value); }
6782 remove { Events.RemoveHandler (CursorChangedEvent, value); }
6784 public event EventHandler DockChanged {
6785 add { Events.AddHandler (DockChangedEvent, value); }
6786 remove { Events.RemoveHandler (DockChangedEvent, value); }
6789 public event EventHandler DoubleClick {
6790 add { Events.AddHandler (DoubleClickEvent, value); }
6791 remove { Events.RemoveHandler (DoubleClickEvent, value); }
6794 public event DragEventHandler DragDrop {
6795 add { Events.AddHandler (DragDropEvent, value); }
6796 remove { Events.RemoveHandler (DragDropEvent, value); }
6799 public event DragEventHandler DragEnter {
6800 add { Events.AddHandler (DragEnterEvent, value); }
6801 remove { Events.RemoveHandler (DragEnterEvent, value); }
6804 public event EventHandler DragLeave {
6805 add { Events.AddHandler (DragLeaveEvent, value); }
6806 remove { Events.RemoveHandler (DragLeaveEvent, value); }
6809 public event DragEventHandler DragOver {
6810 add { Events.AddHandler (DragOverEvent, value); }
6811 remove { Events.RemoveHandler (DragOverEvent, value); }
6814 public event EventHandler EnabledChanged {
6815 add { Events.AddHandler (EnabledChangedEvent, value); }
6816 remove { Events.RemoveHandler (EnabledChangedEvent, value); }
6819 public event EventHandler Enter {
6820 add { Events.AddHandler (EnterEvent, value); }
6821 remove { Events.RemoveHandler (EnterEvent, value); }
6824 public event EventHandler FontChanged {
6825 add { Events.AddHandler (FontChangedEvent, value); }
6826 remove { Events.RemoveHandler (FontChangedEvent, value); }
6829 public event EventHandler ForeColorChanged {
6830 add { Events.AddHandler (ForeColorChangedEvent, value); }
6831 remove { Events.RemoveHandler (ForeColorChangedEvent, value); }
6834 public event GiveFeedbackEventHandler GiveFeedback {
6835 add { Events.AddHandler (GiveFeedbackEvent, value); }
6836 remove { Events.RemoveHandler (GiveFeedbackEvent, value); }
6839 [EditorBrowsable(EditorBrowsableState.Advanced)]
6841 public event EventHandler GotFocus {
6842 add { Events.AddHandler (GotFocusEvent, value); }
6843 remove { Events.RemoveHandler (GotFocusEvent, value); }
6847 [EditorBrowsable(EditorBrowsableState.Advanced)]
6849 public event EventHandler HandleCreated {
6850 add { Events.AddHandler (HandleCreatedEvent, value); }
6851 remove { Events.RemoveHandler (HandleCreatedEvent, value); }
6854 [EditorBrowsable(EditorBrowsableState.Advanced)]
6856 public event EventHandler HandleDestroyed {
6857 add { Events.AddHandler (HandleDestroyedEvent, value); }
6858 remove { Events.RemoveHandler (HandleDestroyedEvent, value); }
6861 public event HelpEventHandler HelpRequested {
6862 add { Events.AddHandler (HelpRequestedEvent, value); }
6863 remove { Events.RemoveHandler (HelpRequestedEvent, value); }
6866 public event EventHandler ImeModeChanged {
6867 add { Events.AddHandler (ImeModeChangedEvent, value); }
6868 remove { Events.RemoveHandler (ImeModeChangedEvent, value); }
6871 [EditorBrowsable(EditorBrowsableState.Advanced)]
6873 public event InvalidateEventHandler Invalidated {
6874 add { Events.AddHandler (InvalidatedEvent, value); }
6875 remove { Events.RemoveHandler (InvalidatedEvent, value); }
6878 public event KeyEventHandler KeyDown {
6879 add { Events.AddHandler (KeyDownEvent, value); }
6880 remove { Events.RemoveHandler (KeyDownEvent, value); }
6883 public event KeyPressEventHandler KeyPress {
6884 add { Events.AddHandler (KeyPressEvent, value); }
6885 remove { Events.RemoveHandler (KeyPressEvent, value); }
6888 public event KeyEventHandler KeyUp {
6889 add { Events.AddHandler (KeyUpEvent, value); }
6890 remove { Events.RemoveHandler (KeyUpEvent, value); }
6893 public event LayoutEventHandler Layout {
6894 add { Events.AddHandler (LayoutEvent, value); }
6895 remove { Events.RemoveHandler (LayoutEvent, value); }
6898 public event EventHandler Leave {
6899 add { Events.AddHandler (LeaveEvent, value); }
6900 remove { Events.RemoveHandler (LeaveEvent, value); }
6903 public event EventHandler LocationChanged {
6904 add { Events.AddHandler (LocationChangedEvent, value); }
6905 remove { Events.RemoveHandler (LocationChangedEvent, value); }
6908 [EditorBrowsable(EditorBrowsableState.Advanced)]
6910 public event EventHandler LostFocus {
6911 add { Events.AddHandler (LostFocusEvent, value); }
6912 remove { Events.RemoveHandler (LostFocusEvent, value); }
6916 public event EventHandler MarginChanged {
6917 add { Events.AddHandler (MarginChangedEvent, value); }
6918 remove {Events.RemoveHandler (MarginChangedEvent, value); }
6922 public event EventHandler MouseCaptureChanged {
6924 internal event EventHandler MouseCaptureChanged {
6926 add { Events.AddHandler (MouseCaptureChangedEvent, value); }
6927 remove { Events.RemoveHandler (MouseCaptureChangedEvent, value); }
6930 public event MouseEventHandler MouseClick
6932 add { Events.AddHandler (MouseClickEvent, value); }
6933 remove { Events.RemoveHandler (MouseClickEvent, value); }
6935 public event MouseEventHandler MouseDoubleClick
6937 add { Events.AddHandler (MouseDoubleClickEvent, value); }
6938 remove { Events.RemoveHandler (MouseDoubleClickEvent, value); }
6941 public event MouseEventHandler MouseDown {
6942 add { Events.AddHandler (MouseDownEvent, value); }
6943 remove { Events.RemoveHandler (MouseDownEvent, value); }
6946 public event EventHandler MouseEnter {
6947 add { Events.AddHandler (MouseEnterEvent, value); }
6948 remove { Events.RemoveHandler (MouseEnterEvent, value); }
6951 public event EventHandler MouseHover {
6952 add { Events.AddHandler (MouseHoverEvent, value); }
6953 remove { Events.RemoveHandler (MouseHoverEvent, value); }
6956 public event EventHandler MouseLeave {
6957 add { Events.AddHandler (MouseLeaveEvent, value); }
6958 remove { Events.RemoveHandler (MouseLeaveEvent, value); }
6961 public event MouseEventHandler MouseMove {
6962 add { Events.AddHandler (MouseMoveEvent, value); }
6963 remove { Events.RemoveHandler (MouseMoveEvent, value); }
6966 public event MouseEventHandler MouseUp {
6967 add { Events.AddHandler (MouseUpEvent, value); }
6968 remove { Events.RemoveHandler (MouseUpEvent, value); }
6971 [EditorBrowsable(EditorBrowsableState.Advanced)]
6973 public event MouseEventHandler MouseWheel {
6974 add { Events.AddHandler (MouseWheelEvent, value); }
6975 remove { Events.RemoveHandler (MouseWheelEvent, value); }
6978 public event EventHandler Move {
6979 add { Events.AddHandler (MoveEvent, value); }
6980 remove { Events.RemoveHandler (MoveEvent, value); }
6983 public event EventHandler PaddingChanged
6985 add { Events.AddHandler (PaddingChangedEvent, value); }
6986 remove { Events.RemoveHandler (PaddingChangedEvent, value); }
6989 public event PaintEventHandler Paint {
6990 add { Events.AddHandler (PaintEvent, value); }
6991 remove { Events.RemoveHandler (PaintEvent, value); }
6994 public event EventHandler ParentChanged {
6995 add { Events.AddHandler (ParentChangedEvent, value); }
6996 remove { Events.RemoveHandler (ParentChangedEvent, value); }
7000 public event PreviewKeyDownEventHandler PreviewKeyDown {
7001 add { Events.AddHandler (PreviewKeyDownEvent, value); }
7002 remove { Events.RemoveHandler (PreviewKeyDownEvent, value); }
7006 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp {
7007 add { Events.AddHandler (QueryAccessibilityHelpEvent, value); }
7008 remove { Events.RemoveHandler (QueryAccessibilityHelpEvent, value); }
7011 public event QueryContinueDragEventHandler QueryContinueDrag {
7012 add { Events.AddHandler (QueryContinueDragEvent, value); }
7013 remove { Events.RemoveHandler (QueryContinueDragEvent, value); }
7017 public event EventHandler RegionChanged {
7018 add { Events.AddHandler (RegionChangedEvent, value); }
7019 remove { Events.RemoveHandler (RegionChangedEvent, value); }
7024 [EditorBrowsable (EditorBrowsableState.Advanced)]
7026 public event EventHandler Resize {
7027 add { Events.AddHandler (ResizeEvent, value); }
7028 remove { Events.RemoveHandler (ResizeEvent, value); }
7031 public event EventHandler RightToLeftChanged {
7032 add { Events.AddHandler (RightToLeftChangedEvent, value); }
7033 remove { Events.RemoveHandler (RightToLeftChangedEvent, value); }
7036 public event EventHandler SizeChanged {
7037 add { Events.AddHandler (SizeChangedEvent, value); }
7038 remove { Events.RemoveHandler (SizeChangedEvent, value); }
7041 public event EventHandler StyleChanged {
7042 add { Events.AddHandler (StyleChangedEvent, value); }
7043 remove { Events.RemoveHandler (StyleChangedEvent, value); }
7046 public event EventHandler SystemColorsChanged {
7047 add { Events.AddHandler (SystemColorsChangedEvent, value); }
7048 remove { Events.RemoveHandler (SystemColorsChangedEvent, value); }
7051 public event EventHandler TabIndexChanged {
7052 add { Events.AddHandler (TabIndexChangedEvent, value); }
7053 remove { Events.RemoveHandler (TabIndexChangedEvent, value); }
7056 public event EventHandler TabStopChanged {
7057 add { Events.AddHandler (TabStopChangedEvent, value); }
7058 remove { Events.RemoveHandler (TabStopChangedEvent, value); }
7061 public event EventHandler TextChanged {
7062 add { Events.AddHandler (TextChangedEvent, value); }
7063 remove { Events.RemoveHandler (TextChangedEvent, value); }
7066 public event EventHandler Validated {
7067 add { Events.AddHandler (ValidatedEvent, value); }
7068 remove { Events.RemoveHandler (ValidatedEvent, value); }
7071 public event CancelEventHandler Validating {
7072 add { Events.AddHandler (ValidatingEvent, value); }
7073 remove { Events.RemoveHandler (ValidatingEvent, value); }
7076 public event EventHandler VisibleChanged {
7077 add { Events.AddHandler (VisibleChangedEvent, value); }
7078 remove { Events.RemoveHandler (VisibleChangedEvent, value); }
7081 #endregion // Events