2 // System.Windows.Forms.Control.cs
5 // stubbed out by Jaak Simm (jaaksimm@firm.ee)
6 // Dennis Hayes (dennish@rayetk.com)
7 // WINELib implementation started by John Sohn (jsohn@columbus.rr.com)
8 // Alexandre Pigolkine (pigolkine@gmx.de)
9 // Aleksey Ryabchuk (ryabchuk@yahoo.com)
11 // (C) Ximian, Inc., 2002
14 using System.ComponentModel;
16 using System.Collections;
17 using System.Threading;
19 using System.Runtime.InteropServices;
20 using System.Collections.Specialized;
22 namespace System.Windows.Forms {
25 /// Defines the base class for controls, which are components with
26 /// visual representation.
29 public class Control : Component , ISynchronizeInvoke, IWin32Window {
32 // Helper NativeWindow class to dispatch messages back
33 // to the Control class
34 protected class ControlNativeWindow : NativeWindow {
36 private Control control;
38 public ControlNativeWindow (Control control) : base() {
39 this.control = control;
42 protected override void WndProc (ref Message m) {
43 //Console.WriteLine ("Control WndProc Message HWnd {0}, Msg {1}", m.HWnd, m.Msg);
44 // Do not call default WndProc here
45 // let the control decide what to do
46 // base.WndProc (ref m);
47 control.WndProc (ref m);
51 // FIXME: not sure if dervied classes should have access
52 protected ControlNativeWindow window;
53 private ControlCollection childControls;
54 private Control parent;
55 static private Hashtable controlsCollection = new Hashtable ();
56 static private NativeWindow parkingWindow = null;
57 private static bool classRegistered = false;
60 // it seems these are stored in case the window is not created,
61 // corresponding properties (below) need to check if window
62 // is created or not and react accordingly
63 string accessibleDefaultActionDescription;
64 string accessibleDescription;
65 string accessibleName;
66 AccessibleRole accessibleRole;
69 protected Color backColor;
70 Image backgroundImage;
71 //BindingContext bindingContext;
75 bool causesValidation;
76 ContextMenu contextMenu;
80 protected Color foreColor;
83 // Point location; // using bounds to store location
86 RightToLeft rightToLeft;
88 protected string text;
89 protected bool visible;
90 protected ControlStyles controlStyles_;
97 private static readonly int LAYOUT_SUSPENDED = BitVector32.CreateMask();
98 private static readonly int LAYOUT_PENDING = BitVector32.CreateMask( LAYOUT_SUSPENDED );
99 private static readonly int DISPOSED = BitVector32.CreateMask( LAYOUT_PENDING );
100 private static readonly int RECREATING_HANDLE= BitVector32.CreateMask( DISPOSED );
101 private static readonly int CREATED = BitVector32.CreateMask( RECREATING_HANDLE );
102 private static readonly int DISPOSING = BitVector32.CreateMask( CREATED );
105 protected bool mouseIsInside_;
107 // BeginInvoke() etc. helpers
108 static int InvokeMessage = Win32.RegisterWindowMessage("mono_control_invoke_helper");
110 // CHECKME: This variable is used to determine whether current thread
111 // was used to create Control Handle. It take some space but saves a call
112 // to unmanaged code in ISynchronizeInvoke.IsInvokeRequired.
113 private int CreatorThreadId_ = 0;
115 private Queue InvokeQueue_ = new Queue();
117 internal class ControlInvokeHelper : IAsyncResult {
118 private Delegate Method_ = null;
119 private object[] MethodArgs_ = null;
120 private object MethodResult_ = null;
121 private ManualResetEvent AsyncWaitHandle_ = new ManualResetEvent(false);
122 private bool CompletedSynchronously_ = false;
123 private bool IsCompleted_ = false;
125 public ControlInvokeHelper( Delegate method, object[] args) {
130 // IAsyncResult interface
131 object IAsyncResult.AsyncState {
133 if( MethodArgs_ != null && MethodArgs_.Length != 0) {
134 return MethodArgs_[MethodArgs_.Length - 1];
140 WaitHandle IAsyncResult.AsyncWaitHandle {
142 return AsyncWaitHandle_;
146 bool IAsyncResult.CompletedSynchronously {
148 return CompletedSynchronously_;
152 bool IAsyncResult.IsCompleted {
158 internal bool CompletedSynchronously {
160 CompletedSynchronously_ = value;
164 internal object MethodResult {
166 return MethodResult_;
170 internal void ExecuteMethod() {
171 object result = Method_.DynamicInvoke(MethodArgs_);
173 MethodResult_ = result;
176 AsyncWaitHandle_.Set();
180 // --- Constructors ---
182 //Compact Framework //only Control()
185 childControls = CreateControlsInstance ();
187 statuses = new BitVector32();
189 accessibleDefaultActionDescription = null;
190 accessibleDescription = null;
191 accessibleName = null;
192 accessibleRole = AccessibleRole.Default;
194 anchor = AnchorStyles.Top | AnchorStyles.Left;
195 backColor = Control.DefaultBackColor;
196 backgroundImage = null;
197 bounds = new Rectangle();
198 oldBounds = new Rectangle();
199 // bindingContext = null;
200 causesValidation = true;
202 dock = DockStyle.None;
204 // font = Control.DefaultFont;
205 foreColor = Control.DefaultForeColor;
206 imeMode = ImeMode.Inherit;
207 isAccessible = false;
208 // location = new Point (0,0); should be from OS
211 rightToLeft = RightToLeft.Inherit;
218 oldBounds.Width = bounds.Width = DefaultSize.Width;
219 oldBounds.Height = bounds.Height= DefaultSize.Height;
220 clientWidth = DefaultSize.Width;
221 clientHeight = DefaultSize.Height;
223 mouseIsInside_ = false;
224 controlStyles_ = ControlStyles.Selectable | ControlStyles.StandardClick | ControlStyles.StandardDoubleClick;
225 // Do not create Handle here, only in CreateHandle
226 // CreateHandle();//sets window handle. FIXME: No it does not
229 // according to docs, the constructors do not create
231 public Control (string text) : this()
234 // SetWindowTextA (Handle, text);
237 public Control (Control parent, string text) : this (text)
240 // SetParent (Handle, parent.Handle);
243 public Control (string text, int left, int top,
244 int width, int height) : this(text)
250 //SetWindowPos (Handle, (IntPtr) 0, left, top,
251 // width, height, 0);
254 public Control (Control parent,string text,int left, int top,
255 int width,int height) : this (parent, text)
261 // SetWindowPos (Handle, (IntPtr) 0, left, top,
262 // width, height, 0);
265 // for internal use only, create a control class
266 // for an existing, created HWND
267 private Control (IntPtr existingHandle)
269 window = (ControlNativeWindow) NativeWindow.FromHandle (
273 // --- Properties ---
274 // Properties only supporting .NET framework, not stubbed out:
275 // - protected bool RenderRightToLeft {get;}
276 // - public IWindowTarget WindowTarget {get; set;}
278 //public AccessibleObject AccessibilityObject {
280 // throw new NotImplementedException ();
284 public string AccessibleDefaultActionDescription {
286 return accessibleDefaultActionDescription;
289 accessibleDefaultActionDescription = value;
293 public string AccessibleDescription {
295 return accessibleDescription;
298 accessibleDescription=value;
302 public string AccessibleName {
304 return accessibleName;
307 accessibleName=value;
311 public AccessibleRole AccessibleRole {
313 return accessibleRole;
316 accessibleRole=value;
320 public virtual bool AllowDrop {
329 public virtual AnchorStyles Anchor {
334 if ( anchor != value ) {
336 if ( anchor != ( AnchorStyles.Left | AnchorStyles.Top ) )
337 Dock = DockStyle.None;
343 public virtual Color BackColor {
348 if( backColor != value) {
350 OnBackColorChanged(new EventArgs());
355 public virtual Image BackgroundImage {
357 return backgroundImage;
360 backgroundImage = value;
361 // FIXME: force redraw
366 public virtual BindingContext BindingContext {
368 //return bindingContext;
369 throw new NotImplementedException ();
372 //bindingContext=value;
373 throw new NotImplementedException ();
385 public Rectangle Bounds {
390 SetBounds(value.Left, value.Top, value.Width, value.Height);
394 public bool CanFocus {
396 if (IsHandleCreated && Visible && Enabled)
403 public bool CanSelect {
405 if ( !GetStyle ( ControlStyles.Selectable ) )
408 if ( Parent == null )
411 Control parent = Parent;
412 while ( parent != null ) {
413 if ( !parent.Visible || !parent.Enabled )
415 parent = parent.Parent;
423 public bool Capture {
425 if (IsHandleCreated) {
426 IntPtr captured = Win32.GetCapture ();
427 if (Handle == captured)
433 if (IsHandleCreated) {
435 Win32.SetCapture (Handle);
437 IntPtr captured = Win32.GetCapture ();
439 // if this window is in capture state
441 if (Handle == captured)
442 Win32.ReleaseCapture ();
448 public bool CausesValidation {
450 return causesValidation;
453 causesValidation=value;
458 public Rectangle ClientRectangle {
460 return new Rectangle ( 0, 0, ClientSize.Width, ClientSize.Height );
467 public Size ClientSize {
469 return new Size ( clientWidth, clientHeight);
472 SetClientSizeCore ( value.Width, value.Height );
477 public string CompanyName {
479 //Better than throwing an execption
480 return "Company Name";
484 public bool ContainsFocus {
486 if (IsHandleCreated) {
487 if (Focused) return true;
488 foreach (Control ctr in Controls) {
489 if (ctr.ContainsFocus) return true;
498 public virtual ContextMenu ContextMenu {
503 if ( contextMenu != value ) {
505 OnContextMenuChanged ( EventArgs.Empty );
510 public ControlCollection Controls {
511 get { return childControls; }
514 public bool Created {
515 get { return statuses[ CREATED ]; }
518 protected virtual CreateParams CreateParams {
520 CreateParams createParams = new CreateParams ();
521 createParams.Caption = Text;
522 createParams.X = Left;
523 createParams.Y = Top;
524 createParams.Width = Width;
525 createParams.Height = Height;
526 createParams.ClassStyle = 0;
527 createParams.ExStyle = 0;
528 createParams.Param = 0;
531 createParams.Parent = parent.Handle;
533 createParams.Parent = ParkingWindowHandle;
535 createParams.Style = (int) WindowStyles.WS_OVERLAPPED;
537 createParams.Style |= (int) WindowStyles.WS_VISIBLE;
544 internal protected IntPtr ControlRealWndProc = IntPtr.Zero;
545 internal protected bool SubClassWndProc_ = false;
547 // This function lets Windows or/and default Windows control process message
548 // Classes have to call it if they do not handle message in WndProc or
549 // default handling is needed.
550 protected void CallControlWndProc( ref Message msg) {
551 if( ControlRealWndProc != IntPtr.Zero) {
552 msg.Result = (IntPtr)Win32.CallWindowProc(ControlRealWndProc, msg.HWnd, (int)msg.Msg, msg.WParam.ToInt32(), msg.LParam.ToInt32());
559 // Subclass only native Windows controls. Those classes have to set SubClassWndProc_ to true in contructor
560 private void SubclassWindow() {
561 if( IsHandleCreated && SubClassWndProc_) {
562 ControlRealWndProc = Win32.SetWindowLong( Handle, GetWindowLongFlag.GWL_WNDPROC, NativeWindow.GetWindowProc());
566 private void UnsubclassWindow() {
567 if( IsHandleCreated) {
568 Win32.SetWindowLong( Handle, GetWindowLongFlag.GWL_WNDPROC, ControlRealWndProc.ToInt32());
572 protected virtual void OnWmCommand (ref Message m) {
573 if( m.LParam.ToInt32() != 0) {
574 if( m.LParam != Handle) {
575 // Control notification
576 System.Console.WriteLine("Control notification Code {0} Id = Hwnd {1}", m.HiWordWParam, m.LParam.ToInt32());
577 Control.ReflectMessage(m.LParam, ref m);
580 // Unhandled Control reflection
581 // Derived class didn't handle WM_COMMAND or called base.WndProc in WM_COMMAND handler
582 // CHECKME: Shall we notify user in debug build, throw an exception or just ignore this case ?
588 public virtual Cursor Cursor {
590 if ( cursor == null )
591 return Cursors.Default;
594 set { cursor = value;}
599 // waiting for BindingContext; should be stubbed now
600 public ControlBindingsCollection DataBindings {
602 throw new NotImplementedException ();
606 public static Color DefaultBackColor {
608 // FIXME: use GetSystemMetrics?
609 return SystemColors.Control;
610 //throw new NotImplementedException ();
615 // FIXME: use GetSystemMetrics?
616 public static Font DefaultFont {
617 // FIXME: get current system font from GenericSansSerif
618 // call ArgumentException not called
620 // throw new NotImplementedException ();
621 // return (FontFamily.GenericSansSerif);
622 return Font.FromHfont(Win32.GetStockObject(GSO_.DEFAULT_GUI_FONT));
626 public static Color DefaultForeColor {
628 return SystemColors.ControlText;
632 protected virtual ImeMode DefaultImeMode {
634 return ImeMode.Inherit;
638 protected virtual Size DefaultSize {
640 //Default label size, this should be correct.
641 return new Size(100,23);
645 public virtual Rectangle DisplayRectangle {
647 return ClientRectangle;
651 public bool Disposing {
652 get { return statuses [ DISPOSING ]; }
655 public virtual DockStyle Dock {
660 if ( dock != value ) {
662 if ( dock != DockStyle.None )
663 Anchor = ( AnchorStyles.Left | AnchorStyles.Top );
664 OnDockChanged ( EventArgs.Empty );
670 public virtual bool Enabled {
673 //return Win32.IsWindowEnabled (Handle);
676 if( enabled != value) {
677 Win32.EnableWindow (Handle, value);
679 // FIXME: Disable/enable all children here
686 public virtual bool Focused {
688 if (IsHandleCreated) {
689 IntPtr focusedWindow = Win32.GetFocus();
690 if (focusedWindow == Handle)
698 public virtual Font Font {
701 if( result == null) {
702 if( Parent != null) {
703 result = Parent.Font;
705 if( result == null) {
706 result = Control.DefaultFont;
713 if( IsHandleCreated) {
714 Win32.SendMessage(Handle, Msg.WM_SETFONT, Font.ToHfont().ToInt32(), 1);
720 protected int FontHeight {
722 throw new NotImplementedException ();
725 throw new NotImplementedException ();
730 public virtual Color ForeColor {
739 public bool HasChildren {
741 if (childControls.Count >0)
750 return bounds.Height;
753 SetBounds(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
757 public ImeMode ImeMode {
767 public bool IsAccessible {
771 } // default is false
777 public bool IsDisposed {
778 get { return statuses [ DISPOSED ]; }
781 public bool IsHandleCreated {
782 get { return window != null && window.Handle != IntPtr.Zero; }
791 SetBounds(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
796 public Point Location {
799 return new Point (Top, Left);
802 SetBounds(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
806 public static Keys ModifierKeys {
808 Keys keys = Keys.None;
810 if ( ( Win32.GetKeyState( (int) VirtualKeys.VK_SHIFT ) & 0x8000 ) == 0x8000 )
812 if ( ( Win32.GetKeyState( (int) VirtualKeys.VK_MENU ) & 0x8000 ) == 0x8000 )
814 if ( ( Win32.GetKeyState( (int) VirtualKeys.VK_CONTROL) & 0x8000) == 0x8000 )
815 keys |= Keys.Control;
823 public static MouseButtons MouseButtons {
825 // FIXME: use GetAsycKeyState?
826 throw new NotImplementedException ();
831 public static Point MousePosition {
833 POINT point = new POINT();
834 Win32.GetCursorPos (ref point);
835 return new Point ( (int) point.x, (int) point.y);
850 public Control Parent {
853 //IntPtr parent = GetParent (Handle);
854 //return FromHandle (parent);
857 if( parent != value) {
858 Console.WriteLine ("setting parent");
861 Console.WriteLine ("add ourself to the parents control");
862 // add ourself to the parents control
863 if ( !parent.Controls.Contains ( this ) )
864 parent.Controls.Add (this);
866 // FIXME: Is this logic correct ?
867 if( BackColor == DefaultBackColor) {
868 if( parent.BackColor != BackColor)
869 OnParentBackColorChanged(new EventArgs());
872 Console.WriteLine ("SetParent");
873 if (IsHandleCreated) {
874 Console.WriteLine ("Handle created");
875 Win32.SetParent (Handle, value.Handle);
878 else if( parent.IsHandleCreated){
879 // CHECKME: Now control is responsible for creating his window
880 // when added to Form, may be things must be reversed.
888 protected static IntPtr ParkingWindowHandle {
890 if ( parkingWindow == null )
891 parkingWindow = new NativeWindow ( );
893 if ( parkingWindow.Handle == IntPtr.Zero ) {
894 CreateParams pars = new CreateParams ( );
895 pars.ClassName = "mono_native_window";
896 pars.Style = (int) WindowStyles.WS_OVERLAPPED;
897 parkingWindow.CreateHandle ( pars );
900 return parkingWindow.Handle;
904 protected static void RegisterDefaultWindowClass ( )
906 if ( !classRegistered ) {
907 WNDCLASS wndClass = new WNDCLASS();
909 wndClass.style = (int) (CS_.CS_OWNDC);
910 wndClass.lpfnWndProc = NativeWindow.GetWindowProc();
911 wndClass.cbClsExtra = 0;
912 wndClass.cbWndExtra = 0;
913 wndClass.hInstance = (IntPtr)0;
914 wndClass.hIcon = (IntPtr)0;
915 wndClass.hCursor = Win32.LoadCursor( (IntPtr)0, LC_.IDC_ARROW);
916 wndClass.hbrBackground = (IntPtr)((int)GetSysColorIndex.COLOR_BTNFACE + 1);
917 wndClass.lpszMenuName = "";
918 wndClass.lpszClassName = Win32.DEFAULT_WINDOW_CLASS;
920 if (Win32.RegisterClass(ref wndClass) != 0)
921 classRegistered = true;
926 public string ProductName {
929 return "Product Name";
934 public string ProductVersion {
937 return "Product Version";
942 public bool RecreatingHandle {
944 return statuses [ RECREATING_HANDLE ] ;
948 public Region Region {
958 protected bool ResizeRedraw {
959 get { return GetStyle ( ControlStyles.ResizeRedraw ); }
960 set { SetStyle ( ControlStyles.ResizeRedraw, value ); }
971 public virtual RightToLeft RightToLeft {
982 protected virtual bool ShowFocusCues {
984 throw new NotImplementedException ();
989 protected bool ShowKeyboardCues {
991 throw new NotImplementedException ();
996 public override ISite Site {
998 throw new NotImplementedException ();
1001 throw new NotImplementedException ();
1008 return new Size(Width, Height);
1011 SetBounds(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
1015 internal int tabindex;//for debug/test only. remove
1017 public int TabIndex {
1026 public bool TabStop {
1047 public virtual string Text {
1049 // CHECKME: if we really need to provide back current text of real window
1050 // or just our copy in text member.
1051 if ( IsHandleCreated ) {
1052 int len = Win32.GetWindowTextLengthA (Handle);
1053 // FIXME: len is doubled due to some strange behaviour.(of GetWindowText function ?)
1054 // instead of 10 characters we can get only 9, even if sb.Capacity is 10.
1055 StringBuilder sb = new StringBuilder(len * 2 /*Win32.GetWindowTextLengthA (Handle)*/);
1056 Win32.GetWindowText (Handle, sb, sb.Capacity);
1057 text = sb.ToString();
1062 if ( text != value ) {
1065 if (IsHandleCreated)
1066 Win32.SetWindowTextA (Handle, value);
1068 OnTextChanged ( EventArgs.Empty );
1079 SetBounds(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
1084 public Control TopLevelControl {
1086 throw new NotImplementedException ();
1090 public bool Visible {
1091 get { return visible; }
1093 SetVisibleCore ( value );
1100 return bounds.Width;
1103 SetBounds(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
1108 /// internal .NET framework supporting methods, not stubbed out:
1109 /// - protected virtual void NotifyInvalidate(Rectangle invalidatedArea)
1110 /// - protected void RaiseDragEvent(object key,DragEventArgs e);
1111 /// - protected void RaiseKeyEvent(object key,KeyEventArgs e);
1112 /// - protected void RaiseMouseEvent(object key,MouseEventArgs e);
1113 /// - protected void RaisePaintEvent(object key,PaintEventArgs e);
1114 /// - protected void ResetMouseEventArgs();
1117 protected void AccessibilityNotifyClients (
1118 AccessibleEvents accEvent,int childID)
1120 throw new NotImplementedException ();
1124 public void BringToFront ()
1126 if ( IsHandleCreated )
1127 Win32.SetWindowPos ( Handle, SetWindowPosZOrder.HWND_TOP, 0, 0, 0, 0,
1128 SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE );
1131 public bool Contains (Control ctl)
1133 return childControls.Contains (ctl);
1136 public void CreateControl ()
1141 statuses [ CREATED ] = true;
1146 protected virtual AccessibleObject CreateAccessibilityInstance() {
1147 throw new NotImplementedException ();
1150 protected virtual ControlCollection CreateControlsInstance ()
1152 return new ControlCollection (this);
1157 public Graphics CreateGraphics ()
1159 return Graphics.FromHwnd(Handle);
1162 protected virtual void CreateHandle ()
1165 throw new ObjectDisposedException ( Name );
1167 if( IsHandleCreated )
1171 window = new ControlNativeWindow (this);
1173 CreateParams createParams = CreateParams;
1175 createParams.Style |= (int)WindowStyles.WS_DISABLED;
1177 window.CreateHandle (createParams);
1179 if( window.Handle != IntPtr.Zero) {
1180 if( !controlsCollection.Contains( window.Handle ) )
1181 controlsCollection.Add( window.Handle, this );
1185 CreatorThreadId_ = Win32.GetCurrentThreadId();
1187 OnHandleCreated ( EventArgs.Empty );
1191 protected virtual void DefWndProc (ref Message m)
1193 window.DefWndProc(ref m);
1196 protected virtual void DestroyHandle ()
1198 if ( IsHandleCreated ) {
1199 if( Handle != IntPtr.Zero) {
1200 controlsCollection.Remove(Handle);
1202 if( window != null) {
1203 window.DestroyHandle ();
1208 protected override void Dispose ( bool disposing )
1211 statuses [ DISPOSING ] = true;
1216 // close/free unmanaged resources
1219 base.Dispose( disposing );
1221 statuses [ DISPOSED ] = true;
1226 public DragDropEffects DoDragDrop (
1227 object data, DragDropEffects allowedEffects)
1229 throw new NotImplementedException ();
1232 //public object EndInvoke(IAsyncResult asyncResult):
1233 //look under ISynchronizeInvoke methods
1236 public Form FindForm ()
1238 throw new NotImplementedException ();
1242 public bool Focus ()
1244 if (Win32.SetFocus (Handle) != (IntPtr) 0)
1250 public static Control FromChildHandle (IntPtr handle)
1252 Control control = null;
1253 IntPtr controlHwnd = handle;
1254 while( controlHwnd != IntPtr.Zero) {
1255 control = controlsCollection[controlHwnd] as Control;
1256 if( control != null) break;
1257 controlHwnd = Win32.GetParent(controlHwnd);
1262 public static Control FromHandle (IntPtr handle)
1264 // FIXME: Here we have to check, whether control already exists
1265 //Control control = new Control (handle);
1266 Control control = controlsCollection[handle] as Control;
1271 public Control GetChildAtPoint (Point pt)
1273 throw new NotImplementedException ();
1277 //public IContainerControl GetContainerControl ()
1279 // throw new NotImplementedException ();
1282 internal Control getNextFocusedControlCore ( Control parent, Control ctl, bool forward )
1284 while ( parent.Parent != null )
1285 parent = parent.Parent;
1287 Control next = parent.GetNextControl ( ctl, forward );
1288 while ( next != null ) {
1289 if ( next.TabStop && next.CanFocus )
1291 next = parent.GetNextControl ( next, forward );
1296 internal Control getNextFocusedControl ( Control parent, bool forward )
1298 Control next = getNextFocusedControlCore ( parent, FocusedControl, forward );
1300 next = getNextFocusedControlCore ( parent, null, forward );
1305 public Control GetNextControl ( Control ctl, bool forward )
1307 Control next = null;
1310 next = Controls.GetFirstControl ( forward );
1313 next = getNextControlForward ( ctl );
1315 next = getNextControlBackward ( ctl );
1320 private Control getNextControlForward ( Control ctl )
1322 if ( ctl.Controls.Count != 0 )
1323 return ctl.Controls.GetFirstControl ( true );
1325 Control parent = ctl.Parent;
1326 if ( parent != null ) {
1327 while ( parent != null ) {
1328 Control next = parent.Controls.GetNextControl ( ctl, true );
1332 parent = parent.Parent;
1337 return Controls.GetFirstControl ( true );
1340 private Control getNextControlBackward ( Control ctl )
1342 Control parent = ctl.Parent;
1343 if ( parent != null ) {
1344 Control next = parent.Controls.GetNextControl ( ctl, false );
1345 if ( next != null ) {
1346 if ( next.Controls.Count > 0 )
1347 return next.Controls.GetFirstControl ( false );
1354 return Controls.GetFirstControl ( false );
1358 protected bool GetStyle (ControlStyles flag)
1360 return (controlStyles_ & flag) != 0;
1364 protected bool GetTopLevel ()
1366 throw new NotImplementedException ();
1375 protected virtual void InitLayout ()
1381 public void Invalidate ()
1383 if (IsHandleCreated) {
1384 Win32.InvalidateRect(Handle, IntPtr.Zero, 1);
1388 public void Invalidate ( bool invalidateChildren )
1391 if ( invalidateChildren ) {
1392 foreach ( Control child in Controls )
1393 child.Invalidate ( invalidateChildren );
1397 // tries to find appropriate owner for modal form
1398 internal static Control getOwnerWindow ( Control skip )
1400 // temporary solution
1401 IEnumerator cw = controlsCollection.GetEnumerator ( );
1403 while ( cw.MoveNext ( ) ) {
1404 Control c = ( (DictionaryEntry) cw.Current).Value as Control;
1405 if ( c != null && c != skip ) {
1406 IntPtr parent = Win32.GetParent ( c.Handle );
1407 IntPtr owner = Win32.GetWindow ( c.Handle, (uint) GetWindowConstants.GW_OWNER );
1408 if ( parent == IntPtr.Zero && owner == IntPtr.Zero )
1416 public void Invalidate (Rectangle rc)
1418 if (IsHandleCreated) {
1419 RECT rect = new RECT();
1420 rect.left = rc.Left;
1422 rect.right = rc.Right;
1423 rect.bottom = rc.Bottom;
1424 Win32.InvalidateRect (Handle, ref rect, true);
1429 public void Invalidate(Region region)
1435 public void Invalidate (Rectangle rc, bool invalidateChildren)
1441 public void Invalidate(Region region,bool invalidateChildren)
1447 protected void InvokeGotFocus (Control toInvoke, EventArgs e)
1453 protected void InvokeLostFocus (Control toInvoke, EventArgs e)
1459 protected void InvokeOnClick (Control toInvoke, EventArgs e)
1465 protected void InvokePaint (Control c, PaintEventArgs e)
1471 protected void InvokePaintBackground (
1472 Control c,PaintEventArgs e)
1478 protected virtual bool IsInputChar (char charCode)
1484 protected virtual bool IsInputKey (Keys keyData)
1489 public static bool IsMnemonic (char charCode, string text)
1493 return text.IndexOf ( "&" + charCode ) > 0;
1497 // methods used with events:
1498 protected virtual void OnBackColorChanged (EventArgs e)
1500 if (BackColorChanged != null)
1501 BackColorChanged (this, e);
1503 foreach( Control ctl in Controls) {
1504 ctl.OnParentBackColorChanged(e);
1508 protected virtual void OnBackgroundImageChanged (EventArgs e)
1510 if (BackgroundImageChanged != null)
1511 BackgroundImageChanged (this, e);
1514 protected virtual void OnBindingContextChanged (EventArgs e)
1516 if (BindingContextChanged != null)
1517 BindingContextChanged (this, e);
1520 protected virtual void OnCausesValidationChanged (EventArgs e)
1522 if (CausesValidationChanged != null)
1523 CausesValidationChanged (this, e);
1526 protected virtual void OnChangeUICues(UICuesEventArgs e)
1528 if (ChangeUICues != null)
1529 ChangeUICues (this, e);
1533 protected virtual void OnClick (EventArgs e)
1540 protected virtual void OnContextMenuChanged (EventArgs e)
1542 if (ContextMenuChanged != null)
1543 ContextMenuChanged (this, e);
1546 protected virtual void OnControlAdded (ControlEventArgs e)
1549 e.Control.CreateControl ( );
1551 e.Control.Visible = Visible;
1553 if (ControlAdded != null)
1554 ControlAdded (this, e);
1557 protected virtual void OnControlRemoved (ControlEventArgs e)
1559 if (ControlRemoved != null)
1560 ControlRemoved (this, e);
1563 protected virtual void OnCreateControl ()
1566 // create all child windows
1567 IEnumerator cw = childControls.GetEnumerator();
1569 while (cw.MoveNext()) {
1570 Console.WriteLine ("Adding Control");
1571 Control control = (Control) cw.Current;
1572 control.CreateControl ();
1577 protected virtual void OnCursorChanged (EventArgs e)
1579 if (CursorChanged != null)
1580 CursorChanged (this, e);
1583 protected virtual void OnDockChanged (EventArgs e)
1585 // changing this property does not affect the control directly
1586 // so have its parent to calculate new layout
1587 if ( Parent != null )
1588 Parent.PerformLayout ( this, "Dock" );
1589 if (DockChanged != null)
1590 DockChanged (this, e);
1593 protected virtual void OnDoubleClick (EventArgs e)
1595 if (DoubleClick != null)
1596 DoubleClick (this, e);
1599 protected virtual void OnDragDrop (DragEventArgs e)
1601 if (DragDrop != null)
1605 protected virtual void OnDragEnter (DragEventArgs e)
1607 if (DragEnter != null)
1608 DragEnter (this, e);
1611 protected virtual void OnDragLeave (EventArgs e)
1613 if (DragLeave != null)
1614 DragLeave (this, e);
1617 protected virtual void OnDragOver (DragEventArgs e)
1619 if (DragOver != null)
1624 protected virtual void OnEnabledChanged (EventArgs e)
1626 if (EnabledChanged != null)
1627 EnabledChanged (this, e);
1630 protected virtual void OnEnter (EventArgs e)
1636 protected virtual void OnFontChanged (EventArgs e)
1638 if (FontChanged != null)
1639 FontChanged (this, e);
1642 protected virtual void OnForeColorChanged (EventArgs e)
1644 if (ForeColorChanged != null)
1645 ForeColorChanged (this, e);
1648 protected virtual void OnGiveFeedback (GiveFeedbackEventArgs e)
1650 if (GiveFeedback != null)
1651 GiveFeedback (this, e);
1655 protected virtual void OnGotFocus (EventArgs e)
1657 if (GotFocus != null)
1661 protected virtual void OnHandleCreated (EventArgs e)
1663 Console.WriteLine ("OnHandleCreated");
1665 //if( font != null) {
1666 // Win32.SendMessage( Handle, Msg.WM_SETFONT, font.ToHfont().ToInt32(), 0);
1668 Win32.SendMessage( Handle, Msg.WM_SETFONT, Font.ToHfont().ToInt32(), 0);
1669 Win32.SetWindowText( Handle, text);
1671 if (HandleCreated != null)
1672 HandleCreated (this, e);
1676 protected virtual void OnHandleDestroyed (EventArgs e)
1678 if( Handle != IntPtr.Zero) {
1679 controlsCollection.Remove(Handle);
1682 if (HandleDestroyed != null) {
1683 HandleDestroyed (this, e);
1687 protected virtual void OnHelpRequested (HelpEventArgs e)
1689 if (HelpRequested != null)
1690 HelpRequested (this, e);
1693 protected virtual void OnImeModeChanged (EventArgs e)
1695 if (ImeModeChanged != null)
1696 ImeModeChanged (this, e);
1699 protected virtual void OnInvalidated (InvalidateEventArgs e)
1701 if (Invalidated != null)
1702 Invalidated (this, e);
1706 protected virtual void OnKeyDown (KeyEventArgs e)
1708 if (KeyDown != null)
1713 protected virtual void OnKeyPress (KeyPressEventArgs e)
1715 if (KeyPress != null)
1720 protected virtual void OnKeyUp (KeyEventArgs e)
1727 protected virtual void OnLayout (LayoutEventArgs e)
1729 DoDockAndAnchorLayout ( e );
1734 protected virtual void OnLeave (EventArgs e)
1740 protected virtual void OnLocationChanged (EventArgs e)
1742 if (LocationChanged != null)
1743 LocationChanged (this, e);
1747 protected virtual void OnLostFocus (EventArgs e)
1749 if (LostFocus != null)
1750 LostFocus (this, e);
1754 protected virtual void OnMouseDown (MouseEventArgs e)
1756 if (MouseDown != null)
1757 MouseDown (this, e);
1760 protected virtual void OnMouseEnter (EventArgs e)
1762 //System.Console.WriteLine("OnMouseEnter");
1763 if (MouseEnter != null)
1764 MouseEnter (this, e);
1767 protected virtual void OnMouseHover (EventArgs e)
1769 if (MouseHover != null)
1770 MouseHover (this, e);
1773 protected virtual void OnMouseLeave (EventArgs e)
1775 //System.Console.WriteLine("OnMouseLeave");
1777 mouseIsInside_ = false;
1778 if (MouseLeave != null)
1779 MouseLeave (this, e);
1783 protected virtual void OnMouseMove (MouseEventArgs e)
1785 // If enter and mouse pressed - do not process
1786 if( ((e.Button & MouseButtons.Left) != 0) && !mouseIsInside_) return;
1788 if( !mouseIsInside_) {
1789 TRACKMOUSEEVENT tme = new TRACKMOUSEEVENT();
1792 tme.dwFlags = (int)TrackerEventFlags.TME_LEAVE;
1793 tme.dwHoverTime = 0;
1795 bool result = Win32.TrackMouseEvent(ref tme);
1797 System.Console.WriteLine("{0}",Win32.FormatMessage(Win32.GetLastError()));
1801 POINT pt = new POINT();
1804 Win32.ClientToScreen(Handle, ref pt);
1805 IntPtr wndUnderMouse = Win32.WindowFromPoint(pt);
1807 if( wndUnderMouse != Handle) {
1808 // we are outside of the window
1809 if( mouseIsInside_) {
1810 OnMouseLeave(new EventArgs());
1811 mouseIsInside_ = false;
1815 if( !mouseIsInside_) {
1816 mouseIsInside_ = true;
1817 OnMouseEnter(new EventArgs());
1820 if (MouseMove != null)
1821 MouseMove (this, e);
1825 protected virtual void OnMouseUp (MouseEventArgs e)
1827 if (MouseUp != null)
1831 protected virtual void OnMouseWheel (MouseEventArgs e)
1833 if (MouseWheel != null)
1834 MouseWheel (this, e);
1837 protected virtual void OnMove (EventArgs e)
1843 protected virtual void OnNotifyMessage (Message m)
1849 protected virtual void OnPaint (PaintEventArgs e)
1856 protected virtual void OnPaintBackground (PaintEventArgs e)
1858 if( GetStyle(ControlStyles.UserPaint)) {
1859 Brush br = new SolidBrush(BackColor);
1860 e.Graphics.FillRectangle(br, e.ClipRectangle);
1865 protected virtual void OnParentBackColorChanged (EventArgs e)
1867 BackColor = Parent.BackColor;
1868 // FIXME: setting BackColor fires the BackColorChanged event,
1869 // so we do not need to call this here
1871 if (BackColorChanged != null)
1872 BackColorChanged (this, e);
1876 protected virtual void OnParentBackgroundImageChanged (
1879 if (BackgroundImageChanged != null)
1880 BackgroundImageChanged (this, e);
1883 protected virtual void OnParentBindingContextChanged (
1886 if (BindingContextChanged != null)
1887 BindingContextChanged (this, e);
1891 protected virtual void OnParentChanged (EventArgs e)
1893 if (ParentChanged != null)
1894 ParentChanged (this, e);
1897 protected virtual void OnParentEnabledChanged (EventArgs e)
1899 if (EnabledChanged != null)
1900 EnabledChanged (this, e);
1903 protected virtual void OnParentFontChanged (EventArgs e)
1905 if (FontChanged != null)
1906 FontChanged (this, e);
1909 protected virtual void OnParentForeColorChanged (EventArgs e)
1911 if (ForeColorChanged != null)
1912 ForeColorChanged (this, e);
1915 protected virtual void OnParentRightToLeftChanged (
1918 if (RightToLeftChanged != null)
1919 RightToLeftChanged (this, e);
1922 protected virtual void OnParentVisibleChanged (EventArgs e)
1924 if (VisibleChanged != null)
1925 VisibleChanged (this, e);
1928 protected virtual void OnQueryContinueDrag (
1929 QueryContinueDragEventArgs e)
1931 if (QueryContinueDrag != null)
1932 QueryContinueDrag (this, e);
1936 protected virtual void OnResize (EventArgs e)
1941 PerformLayout ( this, "Bounds" );
1944 protected virtual void OnRightToLeftChanged (EventArgs e)
1946 if (RightToLeftChanged != null)
1947 RightToLeftChanged (this, e);
1950 protected virtual void OnSizeChanged (EventArgs e)
1953 if (SizeChanged != null)
1954 SizeChanged (this, e);
1957 protected virtual void OnStyleChanged (EventArgs e)
1959 if (StyleChanged != null)
1960 StyleChanged (this, e);
1963 protected virtual void OnSystemColorsChanged (EventArgs e)
1965 if (SystemColorsChanged != null)
1966 SystemColorsChanged (this, e);
1969 protected virtual void OnTabIndexChanged (EventArgs e)
1971 if (TabIndexChanged != null)
1972 TabIndexChanged (this, e);
1975 protected virtual void OnTabStopChanged (EventArgs e)
1977 if (TabStopChanged != null)
1978 TabStopChanged (this, e);
1982 protected virtual void OnTextChanged (EventArgs e)
1984 if (TextChanged != null)
1985 TextChanged (this, e);
1988 //[MonoTODO] // this doesn't seem to be documented
1989 // protected virtual void OnTextAlignChanged (EventArgs e) {
1990 // TextAlignChanged (this, e);
1993 protected virtual void OnValidated (EventArgs e)
1995 if (Validated != null)
1996 Validated (this, e);
2000 // CancelEventArgs not ready
2001 //protected virtual void OnValidating(CancelEventArgs e)
2003 // throw new NotImplementedException ();
2007 protected virtual void OnVisibleChanged (EventArgs e)
2009 if (VisibleChanged != null)
2010 VisibleChanged (this, e);
2014 // --- end of methods for events ---
2018 public void PerformLayout ()
2020 PerformLayout ( null, null );
2024 public void PerformLayout (Control affectedControl,
2025 string affectedProperty)
2027 if ( !statuses [ LAYOUT_SUSPENDED ] )
2028 OnLayout ( new LayoutEventArgs ( affectedControl, affectedProperty ) );
2030 statuses [ LAYOUT_PENDING ] = true;
2035 public Point PointToClient (Point p)
2037 throw new NotImplementedException ();
2042 public Point PointToScreen (Point p)
2044 throw new NotImplementedException ();
2048 public virtual bool PreProcessMessage (ref Message msg)
2050 if ( msg.Msg == Msg.WM_KEYDOWN ) {
2051 Keys keyData = (Keys)msg.WParam.ToInt32( );
2052 if ( !ProcessCmdKey ( ref msg, keyData ) ) {
2053 if ( IsInputKey ( keyData ) )
2056 return ProcessDialogKey ( keyData );
2060 else if ( msg.Msg == Msg.WM_CHAR ) {
2061 if ( IsInputChar ( (char) msg.WParam ) )
2064 return ProcessDialogChar ( (char) msg.WParam );
2071 protected virtual bool ProcessCmdKey (ref Message msg,
2074 // do something with context menu
2076 if ( Parent != null )
2077 return Parent.ProcessCmdKey ( ref msg, keyData );
2082 protected virtual bool ProcessDialogChar (char charCode)
2084 if ( Parent != null )
2085 return Parent.ProcessDialogChar ( charCode );
2090 protected virtual bool ProcessDialogKey (Keys keyData)
2092 if ( Parent != null )
2093 return Parent.ProcessDialogKey ( keyData );
2098 protected virtual bool ProcessKeyEventArgs (ref Message m)
2100 bool handled = false;
2103 case Msg.WM_KEYDOWN:
2104 KeyEventArgs args_down = new KeyEventArgs ( (Keys)m.WParam.ToInt32() );
2105 OnKeyDown ( args_down );
2106 handled = args_down.Handled;
2109 KeyPressEventArgs args_press = new KeyPressEventArgs ( (char) m.WParam );
2110 OnKeyPress ( args_press );
2111 handled = args_press.Handled;
2114 KeyEventArgs args_up = new KeyEventArgs ( (Keys)m.WParam.ToInt32() );
2115 OnKeyUp ( args_up );
2116 handled = args_up.Handled;
2124 protected internal virtual bool ProcessKeyMessage ( ref Message m)
2126 if ( Parent != null ) {
2127 if ( !Parent.ProcessKeyPreview ( ref m ) )
2128 return ProcessKeyEventArgs ( ref m );
2134 protected virtual bool ProcessKeyPreview (ref Message m)
2136 if ( Parent != null )
2137 return Parent.ProcessKeyPreview ( ref m );
2141 // This default implementation of the ProcessMnemonic method simply
2142 // returns false to indicate that the control has no mnemonic.
2143 protected virtual bool ProcessMnemonic (char charCode)
2148 // used when properties/values of Control
2149 // are big enough to warrant recreating the HWND
2150 protected void RecreateHandle()
2152 statuses [ RECREATING_HANDLE ] = true;
2153 if( IsHandleCreated) {
2159 IEnumerator cw = childControls.GetEnumerator();
2160 while ( cw.MoveNext() )
2161 (( Control )cw.Current).RecreateHandle ( );
2164 statuses [ RECREATING_HANDLE ] = false;
2169 public Rectangle RectangleToClient (Rectangle r)
2171 // FIXME: What to return if Handle is not created yet ?
2172 RECT rect = new RECT();
2175 rect.right = r.Right;
2176 rect.bottom = r.Bottom;
2177 Win32.ScreenToClient(Handle,ref rect);
2178 return new Rectangle( rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
2183 public Rectangle RectangleToScreen (Rectangle r)
2185 // FIXME: What to return if Handle is not created yet ?
2186 RECT rect = new RECT();
2189 rect.right = r.Right;
2190 rect.bottom = r.Bottom;
2191 Win32.ClientToScreen(Handle,ref rect);
2192 return new Rectangle( rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
2196 protected static bool ReflectMessage (IntPtr hWnd, ref Message m) {
2197 bool result = false;
2198 Control cntrl = Control.FromHandle( hWnd);
2199 if( cntrl != null) {
2200 cntrl.WndProc(ref m);
2207 public virtual void Refresh ()
2209 //RECT rect = (RECT) null;
2210 //InvalidateRect (Handle, ref rect, true);
2211 Win32.UpdateWindow (Handle);
2215 public virtual void ResetBackColor ()
2221 public void ResetBindings ()
2227 public virtual void ResetFont ()
2233 public virtual void ResetForeColor ()
2239 public void ResetImeMode ()
2245 public virtual void ResetRightToLeft ()
2251 public virtual void ResetText ()
2257 public void ResumeLayout ()
2259 statuses [ LAYOUT_SUSPENDED ] = false;
2260 if ( statuses [ LAYOUT_PENDING ] ) {
2262 statuses [ LAYOUT_PENDING ] = false;
2267 public void ResumeLayout (bool performLayout)
2269 statuses [ LAYOUT_SUSPENDED ] = false;
2270 if ( performLayout && statuses [ LAYOUT_PENDING ] ) {
2272 statuses [ LAYOUT_PENDING ] = false;
2277 protected ContentAlignment RtlTranslateAlignment (
2278 ContentAlignment align)
2280 throw new NotImplementedException ();
2284 protected HorizontalAlignment RtlTranslateAlignment (
2285 HorizontalAlignment align)
2287 throw new NotImplementedException ();
2291 protected LeftRightAlignment RtlTranslateAlignment (
2292 LeftRightAlignment align)
2294 throw new NotImplementedException ();
2298 protected ContentAlignment RtlTranslateContent (
2299 ContentAlignment align)
2301 throw new NotImplementedException ();
2305 protected HorizontalAlignment RtlTranslateHorizontal (
2306 HorizontalAlignment align)
2308 throw new NotImplementedException ();
2312 protected LeftRightAlignment RtlTranslateLeftRight (
2313 LeftRightAlignment align)
2315 throw new NotImplementedException ();
2319 public void Scale (float ratio)
2321 Scale ( ratio, ratio );
2325 public void Scale (float dx,float dy)
2328 ScaleCore ( dx, dy );
2329 IEnumerator cw = childControls.GetEnumerator();
2330 while ( cw.MoveNext() ) {
2331 Control control = (Control) cw.Current;
2332 control.Scale ( dx, dy );
2338 protected virtual void ScaleCore (float dx, float dy)
2340 Location = new Point ( (int) (Left * dx), (int) (Top * dy) );
2341 ClientSize = new Size ((int) ( ClientSize.Width * dx ),
2342 (int) ( ClientSize.Height * dy) );
2346 public void Select ()
2352 protected virtual void Select (bool directed,bool forward)
2358 public bool SelectNextControl (Control ctl, bool forward,
2360 bool nested, bool wrap)
2362 throw new NotImplementedException ();
2367 public void SendToBack ()
2373 public void SetBounds (int x, int y, int width, int height)
2375 SetBounds(x, y, width, height, BoundsSpecified.All);
2379 public void SetBounds (int x, int y, int width, int height, BoundsSpecified specified)
2381 SetBoundsCore( x, y, width, height, specified);
2385 protected virtual void SetBoundsCore ( int x, int y, int width, int height, BoundsSpecified specified)
2387 if( (specified & BoundsSpecified.X) == 0) x = Left;
2388 if( (specified & BoundsSpecified.Y) == 0) y = Top;
2389 if( (specified & BoundsSpecified.Width) == 0) width = Width;
2390 if( (specified & BoundsSpecified.Height) == 0) height = Height;
2392 if( IsHandleCreated ) {
2393 SetWindowPosFlags flags = SetWindowPosFlags.SWP_NOZORDER | SetWindowPosFlags.SWP_FRAMECHANGED | SetWindowPosFlags.SWP_DRAWFRAME;
2394 Win32.SetWindowPos( Handle, SetWindowPosZOrder.HWND_NOTOPMOST, x, y, width, height, flags);
2397 UpdateBounds( x, y, width, height );
2400 protected virtual bool MenuPresent {
2401 get { return false; }
2405 protected virtual void SetClientSizeCore (int x, int y)
2407 RECT rc = new RECT();
2411 CreateParams pars = CreateParams;
2412 Win32.AdjustWindowRectEx ( ref rc, pars.Style, MenuPresent ? 1 : 0, pars.ExStyle );
2414 Size = new Size( rc.right - rc.left, rc.bottom - rc.top );
2418 protected void SetStyle (ControlStyles flag, bool value)
2421 controlStyles_ |= flag;
2424 controlStyles_ &= ~flag;
2428 protected void SetTopLevel (bool value)
2431 // FIXME: verify on whether this is supposed
2432 // to activate/deactive the window
2433 Win32.SetWindowPos (Handle,
2434 SetWindowPosZOrder.HWND_NOTOPMOST,
2437 // FIXME: this does not make sense but
2438 // the docs say the window is hidden
2439 Win32.ShowWindow (Handle, ShowWindowStyles.SW_HIDE);
2443 protected virtual void SetVisibleCore ( bool value )
2445 bool visibleChanged = ( visible != value );
2449 if ( visibleChanged )
2450 OnVisibleChanged ( EventArgs.Empty );
2452 if ( IsHandleCreated ) {
2453 SetWindowPosFlags flags = value ? SetWindowPosFlags.SWP_SHOWWINDOW : SetWindowPosFlags.SWP_HIDEWINDOW;
2454 flags |= SetWindowPosFlags.SWP_NOZORDER | SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE;
2455 Win32.SetWindowPos( Handle, 0, 0, 0, 0, 0, flags );
2458 foreach ( Control c in Controls )
2467 public void SuspendLayout ()
2469 statuses [ LAYOUT_SUSPENDED ] = true;
2473 public void Update ()
2475 Win32.UpdateWindow (Handle);
2479 protected void UpdateBounds ()
2480 { // update control bounds with current size and position
2482 // currently, this function is called in responce to
2483 // window events, so I assume that all window handles
2485 RECT rect = new RECT ( );
2486 Win32.GetWindowRect ( Handle, ref rect );
2488 IntPtr parent = Win32.GetParent ( Handle );
2489 if ( parent != IntPtr.Zero ) {
2490 Win32.ScreenToClient( parent, ref rect );
2493 UpdateBounds ( rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top );
2497 protected void UpdateBounds (int x, int y, int width, int height)
2499 int clWidth = width;
2500 int clHeight = height;
2502 CreateParams pars = CreateParams;
2503 // this check should be removed when all controls will use base
2504 // implementation of CreateParams
2505 if ( pars != null ) {
2506 RECT rc = new RECT();
2510 Win32.AdjustWindowRectEx ( ref rc, pars.Style, MenuPresent ? 1 : 0, pars.ExStyle );
2512 clWidth -= ( ( rc.right - rc.left ) - clWidth );
2513 clHeight -= ( ( rc.bottom - rc.top ) - clHeight);
2516 UpdateBounds ( x , y, width, height, clWidth, clHeight );
2520 protected void UpdateBounds (
2521 int x, int y, int width, int height, int clientWidth,
2524 oldBounds.X = bounds.X;
2525 oldBounds.Y = bounds.Y;
2526 oldBounds.Width = bounds.Width;
2527 oldBounds.Height = bounds.Height;
2529 bool bLocationChanged = ( bounds.X != x ) || ( bounds.Y != y );
2533 bool bSizeChanged = ( bounds.Width != width ) || ( bounds.Height != height );
2534 bounds.Width = width;
2535 bounds.Height = height;
2537 this.clientWidth = clientWidth;
2538 this.clientHeight = clientHeight;
2540 if ( bLocationChanged )
2541 OnLocationChanged ( EventArgs.Empty );
2543 OnSizeChanged ( EventArgs.Empty );
2547 protected void UpdateStyles ()
2553 protected void UpdateZOrder ()
2555 if ( !IsHandleCreated || Parent == null )
2558 int position = Parent.Controls.GetChildIndex ( this , false );
2559 switch ( position ) {
2563 // not in collection for some reason
2567 Control prev = Parent.Controls [ position - 1 ];
2568 if ( prev.IsHandleCreated )
2569 Win32.SetWindowPos( Handle, prev.Handle, 0, 0, 0, 0, SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE );
2575 internal MouseEventArgs Msg2MouseEventArgs( ref Message msg) {
2576 MouseButtons mb = MouseButtons.None;
2577 KeyStatusFlags keyIndicator = (KeyStatusFlags)msg.WParam.ToInt32();
2578 if( (keyIndicator & KeyStatusFlags.MK_LBUTTON) != 0) {
2579 mb |= MouseButtons.Left;
2581 if( (keyIndicator & KeyStatusFlags.MK_RBUTTON) != 0) {
2582 mb |= MouseButtons.Right;
2584 if( (keyIndicator & KeyStatusFlags.MK_MBUTTON) != 0) {
2585 mb |= MouseButtons.Middle;
2587 if( (keyIndicator & KeyStatusFlags.MK_XBUTTON1) != 0) {
2588 mb |= MouseButtons.XButton1;
2590 if( (keyIndicator & KeyStatusFlags.MK_XBUTTON2) != 0) {
2591 mb |= MouseButtons.XButton2;
2594 return new MouseEventArgs( mb, (mb != MouseButtons.None) ? 1: 0, msg.LoWordLParam, msg.HiWordLParam, 0);
2597 // WndProc - calls appriate On... function for the give
2600 // These On... functions do not appear to be called by
2603 // background color/image handled by WinForms
2604 // OnBackColorChanged
2605 // OnBackgroundImageChanged
2606 // OnForeColorChanged
2607 // OnPaintBackground
2609 // controls are added/removed by WinForms
2614 // OnBindingContextChanged
2615 // OnCausesValidationChanged
2617 // OnContextMenuChanged
2618 // OnRightToLeftChanged
2623 // OnTextAlignChanged
2626 // OnTabIndexChanged
2628 // OnLocationChanged
2630 // FIXME: may be one of the WM_IME_ messages
2633 // InvalidateRect is called by no Invalidate message exists
2636 // these messages ARE not called by WNDPROC according to docs
2637 // OnParentBackColorChanged
2638 // OnParentBackgroundImageChanged
2639 // OnParentBindingContextChanged
2641 // OnParentEnabledChanged
2642 // OnParentFontChanged
2643 // OnParentForeColorChanged
2644 // OnParentRightToLeftChanged
2645 // OnParentVisibleChanged
2647 protected virtual void WndProc(ref Message m)
2649 EventArgs eventArgs = new EventArgs ();
2650 // FIXME: paintEventArgs is not being created properly
2651 // FIXME: Graphics does not have a public constructor, you must get one from .NET
2652 //PaintEventArgs paintEventArgs = new PaintEventArgs (
2653 // new Graphics(), new Rectangle());
2655 if( (uint)m.Msg == Control.InvokeMessage) {
2656 ControlInvokeHelper helper = null;
2657 lock( InvokeQueue_.SyncRoot) {
2658 if( InvokeQueue_.Count > 0) {
2659 helper = (ControlInvokeHelper)InvokeQueue_.Dequeue();
2662 if( helper != null) {
2663 helper.ExecuteMethod();
2667 else if( m.Msg == Msg.WM_COMMAND) {
2669 m.Result = (IntPtr)1;
2670 OnWmCommand (ref m);
2671 if( m.Result != IntPtr.Zero) {
2672 CallControlWndProc (ref m);
2679 Console.WriteLine ("WM_CREATE");
2680 OnHandleCreated (eventArgs);
2682 case Msg.WM_LBUTTONDBLCLK:
2683 OnDoubleClick (eventArgs);
2684 CallControlWndProc(ref m);
2690 // OnQueryContinueDrag
2692 OnEnabledChanged (eventArgs);
2693 CallControlWndProc(ref m);
2695 case Msg.WM_SETFOCUS:
2696 OnEnter (eventArgs);
2697 OnGotFocus (eventArgs);
2698 CallControlWndProc(ref m);
2700 case Msg.WM_FONTCHANGE:
2701 OnFontChanged (eventArgs);
2702 CallControlWndProc(ref m);
2704 case Msg.WM_DESTROY:
2705 OnHandleDestroyed (eventArgs);
2706 CallControlWndProc(ref m);
2710 //OnHelpRequested (eventArgs);
2711 CallControlWndProc(ref m);
2713 case Msg.WM_KEYDOWN:
2714 if ( !ProcessKeyMessage ( ref m ) )
2715 CallControlWndProc( ref m );
2718 if ( !ProcessKeyMessage ( ref m ) )
2719 CallControlWndProc( ref m );
2722 if ( !ProcessKeyMessage ( ref m ) )
2723 CallControlWndProc( ref m );
2725 case Msg.WM_KILLFOCUS:
2726 OnLeave (eventArgs);
2727 OnLostFocus (eventArgs);
2728 CallControlWndProc(ref m);
2730 case Msg.WM_MOUSEACTIVATE:
2731 //OnMouseEnter (eventArgs);
2732 CallControlWndProc(ref m);
2734 case Msg.WM_MOUSEHOVER: // called by TrackMouseEvent
2735 OnMouseHover (eventArgs);
2736 CallControlWndProc(ref m);
2738 case Msg.WM_MOUSELEAVE: // called by TrackMouseEvent
2739 OnMouseLeave (eventArgs);
2740 CallControlWndProc(ref m);
2742 case Msg.WM_MOUSEMOVE:
2744 OnMouseMove (Msg2MouseEventArgs(ref m));
2745 CallControlWndProc(ref m);
2747 case Msg.WM_LBUTTONDOWN:
2749 //OnMouseDown (eventArgs);
2750 CallControlWndProc(ref m);
2752 case Msg.WM_LBUTTONUP:
2754 //OnMouseUp (eventArgs);
2755 CallControlWndProc(ref m);
2757 case Msg.WM_MOUSEWHEEL:
2759 //OnMouseWheel (eventArgs);
2760 CallControlWndProc(ref m);
2765 CallControlWndProc(ref m);
2768 NMHDR nmhdr = (NMHDR)Marshal.PtrToStructure ( m.LParam,
2770 if( !Control.ReflectMessage( nmhdr.hwndFrom, ref m ))
2771 CallControlWndProc(ref m);
2773 // FIXME: get NM_CLICKED msg from pnmh
2774 // OnClick (eventArgs);
2775 //OnNotifyMessage (eventArgs);
2777 case Msg.WM_ERASEBKGND:
2778 if( GetStyle(ControlStyles.UserPaint)){
2779 if( !GetStyle(ControlStyles.AllPaintingInWmPaint)) {
2780 PaintEventArgs eraseEventArgs = new PaintEventArgs( Graphics.FromHdc(m.WParam), new Rectangle(new Point(0,0),Size));
2781 OnPaintBackground(eraseEventArgs);
2782 eraseEventArgs.Dispose();
2784 m.Result = (IntPtr)1;
2787 CallControlWndProc(ref m);
2791 if( !GetStyle(ControlStyles.UserPaint)) {
2792 CallControlWndProc(ref m);
2795 PAINTSTRUCT ps = new PAINTSTRUCT();
2796 IntPtr hdc = Win32.BeginPaint( Handle, ref ps);
2797 Rectangle rc = new Rectangle();
2798 rc.X = ps.rcPaint.left;
2799 rc.Y = ps.rcPaint.top;
2800 rc.Width = ps.rcPaint.right - ps.rcPaint.left;
2801 rc.Height = ps.rcPaint.bottom - ps.rcPaint.top;
2802 PaintEventArgs paintEventArgs = new PaintEventArgs( Graphics.FromHdc(hdc), rc);
2803 if( GetStyle(ControlStyles.AllPaintingInWmPaint)) {
2804 OnPaintBackground(paintEventArgs);
2806 OnPaint (paintEventArgs);
2807 paintEventArgs.Dispose();
2808 Win32.EndPaint(Handle, ref ps);
2812 if( GetStyle(ControlStyles.ResizeRedraw)) {
2815 CallControlWndProc(ref m);
2817 case Msg.WM_WINDOWPOSCHANGED:
2819 CallControlWndProc(ref m);
2821 case Msg.WM_STYLECHANGED:
2822 OnStyleChanged (eventArgs);
2823 CallControlWndProc(ref m);
2825 case Msg.WM_SYSCOLORCHANGE:
2826 OnSystemColorsChanged (eventArgs);
2827 CallControlWndProc(ref m);
2829 case Msg.WM_SETTEXT:
2830 //OnTextChanged (eventArgs);
2831 CallControlWndProc(ref m);
2833 case Msg.WM_SETFONT:
2834 //OnTextChanged (eventArgs);
2835 CallControlWndProc(ref m);
2837 case Msg.WM_SHOWWINDOW:
2838 OnVisibleChanged (eventArgs);
2839 CallControlWndProc(ref m);
2841 case Msg.WM_CTLCOLORLISTBOX:
2842 Win32.SetTextColor( m.WParam, Win32.RGB(ForeColor));
2843 //Win32.SetBkColor( m.WParam, 0x00FF00);
2844 //m.Result = Win32.GetStockObject(GSO_.LTGRAY_BRUSH);
2846 case Msg.WM_MEASUREITEM:
2847 ReflectMessage( m.WParam, ref m);
2849 case Msg.WM_DRAWITEM:
2850 Control.ReflectMessage( m.WParam, ref m);
2852 case Msg.WM_HSCROLL:
2853 case Msg.WM_VSCROLL:
2854 if(!Control.ReflectMessage( m.LParam, ref m )) {
2855 CallControlWndProc(ref m);
2858 case Msg.WM_SETCURSOR:
2859 if ( cursor != null && cursor.Handle != IntPtr.Zero ) {
2860 Win32.SetCursor ( cursor.Handle );
2861 m.Result = (IntPtr)1;
2863 CallControlWndProc( ref m );
2865 case Msg.WM_RBUTTONDOWN:
2866 if ( contextMenu != null ) {
2867 contextMenu.Show ( this,
2868 new Point ( Win32.HIGH_ORDER ( m.LParam.ToInt32() ),
2869 Win32.LOW_ORDER ( m.LParam.ToInt32() ) ) );
2871 CallControlWndProc( ref m );
2874 CallControlWndProc(ref m);
2876 if( ControlRealWndProc != IntPtr.Zero) {
2877 CallControlWndProc(ref m);
2887 private void DoAnchor(Control ctrl) {
2888 int deltaWidth = Bounds.Width - oldBounds.Width;
2889 int deltaHeight = Bounds.Height - oldBounds.Height;
2890 int halfDeltaWidth = deltaWidth / 2;
2891 int halfDeltaHeight = deltaHeight / 2;
2892 Rectangle controlBounds = ctrl.Bounds;
2893 if ((ctrl.Anchor & AnchorStyles.Left) == 0) {
2894 controlBounds.X += halfDeltaWidth;
2896 if ((ctrl.Anchor & AnchorStyles.Top) == 0) {
2897 controlBounds.Y += halfDeltaHeight;
2899 if ((ctrl.Anchor & AnchorStyles.Right) == AnchorStyles.Right) {
2900 if ((ctrl.Anchor & AnchorStyles.Left) == AnchorStyles.Left) {
2901 controlBounds.Width += deltaWidth;
2904 controlBounds.X += halfDeltaWidth;
2907 if ((ctrl.Anchor & AnchorStyles.Bottom) == AnchorStyles.Bottom) {
2908 if ((ctrl.Anchor & AnchorStyles.Top) == AnchorStyles.Top) {
2909 controlBounds.Height += deltaHeight;
2912 controlBounds.Y += halfDeltaHeight;
2915 ctrl.Bounds = controlBounds;
2918 private void DoDockAndAnchorLayout ( LayoutEventArgs e ) {
2919 Rectangle area = DisplayRectangle;
2921 for ( int i = childControls.Count - 1; i >= 0; i-- ) {
2922 Control control = childControls[i];
2924 switch ( control.Dock ) {
2925 case DockStyle.Bottom:
2926 control.SetBounds ( area.Left, area.Bottom - control.Height,
2927 area.Width, control.Height );
2928 area.Height -= control.Height;
2931 control.SetBounds ( area.Left, area.Y, area.Width, control.Height );
2932 area.Y += control.Height;
2933 area.Height -= control.Height;
2935 case DockStyle.Right:
2936 control.SetBounds ( area.Right - control.Width, area.Top,
2937 control.Width, area.Height );
2938 area.Width -= control.Width;
2940 case DockStyle.Left:
2941 control.SetBounds ( area.Left, area.Y, control.Width, area.Height );
2942 area.X += control.Width;
2943 area.Width -= control.Width;
2945 case DockStyle.None:
2951 for ( int i = childControls.Count - 1; i >= 0; i-- ) {
2952 Control control = childControls[i];
2954 if ( control.Dock == DockStyle.Fill ) {
2955 control.SetBounds ( area.X, area.Y, area.Width, area.Height );
2960 internal static Control FocusedControl {
2962 IEnumerator cw = controlsCollection.GetEnumerator ( );
2964 while ( cw.MoveNext ( ) ) {
2965 Control c = ( (DictionaryEntry) cw.Current).Value as Control;
2967 if ( c.Focused ) return c;
2974 internal Control getParentForm ( )
2976 Control parent = this.Parent;
2977 while ( parent != null ) {
2978 if ( parent is Form )
2980 parent = parent.Parent;
2985 /// --- Control: events ---
2986 public event EventHandler BackColorChanged;
2987 public event EventHandler BackgroundImageChanged;
2988 public event EventHandler BindingContextChanged;
2989 public event EventHandler CausesValidationChanged;
2990 public event UICuesEventHandler ChangeUICues;
2993 public event EventHandler Click;
2995 public event EventHandler ContextMenuChanged;
2996 public event ControlEventHandler ControlAdded;
2997 public event ControlEventHandler ControlRemoved;
2998 public event EventHandler CursorChanged;
2999 public event EventHandler DockChanged;
3000 public event EventHandler DoubleClick;
3001 public event DragEventHandler DragDrop;
3002 public event DragEventHandler DragEnter;
3003 public event EventHandler DragLeave;
3004 public event DragEventHandler DragOver;
3007 public event EventHandler EnabledChanged;
3009 public event EventHandler Enter;
3010 public event EventHandler FontChanged;
3011 public event EventHandler ForeColorChanged;
3012 public event GiveFeedbackEventHandler GiveFeedback;
3015 public event EventHandler GotFocus;
3017 public event EventHandler HandleCreated;
3018 public event EventHandler HandleDestroyed;
3019 public event HelpEventHandler HelpRequested;
3020 public event EventHandler ImeModeChanged;
3021 public event InvalidateEventHandler Invalidated;
3024 public event KeyEventHandler KeyDown;
3027 public event KeyPressEventHandler KeyPress;
3030 public event KeyEventHandler KeyUp;
3032 public event LayoutEventHandler Layout;
3033 public event EventHandler Leave;
3034 public event EventHandler LocationChanged;
3037 public event EventHandler LostFocus;
3040 public event MouseEventHandler MouseDown;
3042 public event EventHandler MouseEnter;
3043 public event EventHandler MouseHover;
3044 public event EventHandler MouseLeave;
3047 public event MouseEventHandler MouseMove;
3050 public event MouseEventHandler MouseUp;
3052 public event MouseEventHandler MouseWheel;
3053 public event EventHandler Move;
3056 public event PaintEventHandler Paint;
3059 public event EventHandler ParentChanged;
3061 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp;
3062 public event QueryContinueDragEventHandler QueryContinueDrag;
3065 public event EventHandler Resize;
3067 public event EventHandler RightToLeftChanged;
3068 public event EventHandler SizeChanged;
3069 public event EventHandler StyleChanged;
3070 public event EventHandler SystemColorsChanged;
3071 public event EventHandler TabIndexChanged;
3072 public event EventHandler TabStopChanged;
3075 public event EventHandler TextChanged;
3077 public event EventHandler Validated;
3079 // CancelEventHandler not yet defined
3080 //public event CancelEventHandler Validating {
3082 public event EventHandler VisibleChanged;
3084 /// --- IWin32Window properties
3085 public IntPtr Handle {
3087 // If the handle has not yet been created,
3088 // referencing this property will force the
3089 // handle to be created. ( MSDN )
3091 if ( !IsHandleCreated )
3094 return window.Handle;
3098 /// --- ISynchronizeInvoke properties ---
3100 public bool InvokeRequired {
3102 return CreatorThreadId_ != Win32.GetCurrentThreadId();
3106 private IAsyncResult DoInvoke( Delegate method, object[] args) {
3107 IAsyncResult result = null;
3108 ControlInvokeHelper helper = new ControlInvokeHelper(method, args);
3109 if( InvokeRequired) {
3111 lock( InvokeQueue_.SyncRoot) {
3112 InvokeQueue_.Enqueue(helper);
3114 Win32.PostMessage(Handle, Control.InvokeMessage, 0, 0);
3119 helper.CompletedSynchronously = true;
3120 helper.ExecuteMethod();
3126 /// --- ISynchronizeInvoke methods ---
3128 public IAsyncResult BeginInvoke (Delegate method)
3130 return DoInvoke( method, null);
3134 public IAsyncResult BeginInvoke (Delegate method, object[] args)
3136 return DoInvoke( method, args);
3140 public object EndInvoke (IAsyncResult asyncResult)
3142 object result = null;
3143 ControlInvokeHelper helper = asyncResult as ControlInvokeHelper;
3144 if( helper != null) {
3145 if( !asyncResult.CompletedSynchronously) {
3146 asyncResult.AsyncWaitHandle.WaitOne();
3148 result = helper.MethodResult;
3155 public object Invoke (Delegate method)
3157 return Invoke( method, null);
3161 public object Invoke (Delegate method, object[] args)
3163 IAsyncResult result = BeginInvoke(method, args);
3164 return EndInvoke(result);
3167 /// sub-class: Control.ControlAccessibleObject
3169 /// Provides information about a control that can be used by an accessibility application.
3171 public class ControlAccessibleObject : AccessibleObject {
3172 // AccessibleObject not ready to be base class
3173 /// --- ControlAccessibleObject.constructor ---
3175 public ControlAccessibleObject (Control ownerControl)
3177 throw new NotImplementedException ();
3181 /// --- ControlAccessibleObject Properties ---
3183 public override string DefaultAction {
3186 return base.DefaultAction;
3191 public override string Description {
3194 return base.Description;
3199 public IntPtr Handle {
3201 throw new NotImplementedException ();
3209 public override string Help {
3217 public override string KeyboardShortcut {
3220 return base.KeyboardShortcut;
3225 public override string Name {
3237 public Control Owner {
3239 throw new NotImplementedException ();
3244 public override AccessibleRole Role {
3251 /// --- ControlAccessibleObject Methods ---
3253 public override int GetHelpTopic(out string fileName)
3256 return base.GetHelpTopic(out fileName);
3260 public void NotifyClients (AccessibleEvents accEvent)
3266 public void NotifyClients (AccessibleEvents accEvent,
3273 public override string ToString ()
3276 return base.ToString();
3280 /// sub-class: Control.ControlCollection
3282 /// Represents a collection of Control objects
3284 public class ControlCollection : IList, ICollection, IEnumerable, ICloneable {
3286 class ControlComparer : IComparer {
3288 int IComparer.Compare( object x, object y )
3290 int tx = ( ( Control )x ).TabIndex;
3291 int ty = ( ( Control )y ).TabIndex;
3302 private ArrayList collection = new ArrayList ();
3303 protected Control owner;
3305 /// --- ControlCollection.constructor ---
3306 public ControlCollection (Control owner)
3311 /// --- ControlCollection Properties ---
3314 return collection.Count;
3318 public bool IsReadOnly {
3320 return collection.IsReadOnly;
3324 public virtual Control this [int index] {
3326 return (Control) collection[index];
3330 public virtual void Add (Control value)
3332 if( !Contains(value)) {
3333 collection.Add (value);
3334 value.Parent = owner;
3335 owner.OnControlAdded ( new ControlEventArgs ( value ) );
3339 public virtual void AddRange (Control[] controls)
3341 for(int i = 0; i < controls.Length; i++) {
3346 public virtual void Clear ()
3348 collection.Clear ();
3351 public bool Contains (Control control)
3353 return collection.Contains (control);
3356 public void CopyTo (Array dest,int index)
3358 collection.CopyTo (dest, index);
3362 public override bool Equals (object obj)
3365 return base.Equals(obj);
3368 public int GetChildIndex ( Control child )
3370 return GetChildIndex ( child, true );
3373 public int GetChildIndex ( Control child, bool throwException )
3375 int index = collection.IndexOf ( child );
3376 if ( index == -1 && throwException )
3377 throw new ArgumentException( "'child' is not a child control of this parent.");
3381 public IEnumerator GetEnumerator ()
3383 return collection.GetEnumerator ();
3387 public override int GetHashCode ()
3390 return base.GetHashCode();
3393 public int IndexOf (Control control)
3395 return collection.IndexOf (control);
3398 public virtual void Remove (Control value)
3400 collection.Remove (value);
3403 public void RemoveAt (int index)
3405 Remove ( this [ index ] );
3406 // have to give a chance to handle this situation in derived class
3407 //collection.RemoveAt (index);
3410 public void SetChildIndex ( Control child, int newIndex )
3412 int oldIndex = collection.IndexOf ( child );
3413 if ( oldIndex == -1 )
3414 throw new ArgumentException( "'child' is not a child control of this parent.");
3416 if ( oldIndex != newIndex ) {
3417 collection.Remove ( child );
3419 if ( newIndex >= collection.Count )
3420 collection.Add ( child );
3422 collection.Insert ( newIndex, child );
3426 internal Control GetFirstControl ( bool direction )
3428 if ( collection.Count == 0 )
3431 ArrayList copy = collection.Clone ( ) as ArrayList;
3432 copy.Sort ( new ControlComparer ( ) );
3435 return copy [0] as Control;
3437 Control last = copy[ collection.Count - 1 ] as Control;
3438 if ( last.Controls.Count == 0 )
3441 return last.Controls.GetFirstControl ( false );
3446 internal Control GetNextControl ( Control ctl, bool forward )
3448 if ( collection.Count == 0 )
3451 ArrayList copy = collection.Clone ( ) as ArrayList;
3452 copy.Sort ( new ControlComparer ( ) );
3454 int index = copy.IndexOf ( ctl ) + ( forward ? 1 : -1 );
3456 if ( ( forward && index < copy.Count ) || ( !forward && index >= 0 ) )
3457 return copy[index] as Control;
3462 /// --- ControlCollection.IClonable methods ---
3464 object ICloneable.Clone ()
3466 throw new NotImplementedException ();
3469 /// --- ControlCollection.IList properties ---
3470 bool IList.IsFixedSize {
3472 return collection.IsFixedSize;
3476 object IList.this [int index] {
3478 return collection[index];
3481 collection[index] = value;
3485 object ICollection.SyncRoot {
3487 return collection.SyncRoot;
3491 bool ICollection.IsSynchronized {
3493 return collection.IsSynchronized;
3497 /// --- ControlCollection.IList methods ---
3498 int IList.Add (object control)
3500 return collection.Add (control);
3503 bool IList.Contains (object control)
3505 return collection.Contains (control);
3508 int IList.IndexOf (object control)
3510 return collection.IndexOf (control);
3513 void IList.Insert (int index,object value)
3515 collection.Insert (index, value);
3518 void IList.Remove (object control)
3520 collection.Remove (control);
3522 } // --- end of Control.ControlCollection ---