* TextBoxBase.cs: Use the new SuspendRecalc/ResumeRecalc methods
[mono-project.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / Form.cs
blob6a456a5db791801ce7f5dc4b63543349be1b25c0
1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
8 //
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
11 //
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2004-2006 Novell, Inc.
22 // Authors:
23 // Peter Bartok pbartok@novell.com
26 // NOT COMPLETE
28 using System;
29 using System.Drawing;
30 using System.ComponentModel;
31 using System.ComponentModel.Design;
32 using System.ComponentModel.Design.Serialization;
33 using System.Collections;
34 using System.Runtime.InteropServices;
35 using System.Threading;
37 namespace System.Windows.Forms {
38 [DesignerCategory("Form")]
39 [DesignTimeVisible(false)]
40 [Designer("System.Windows.Forms.Design.FormDocumentDesigner, " + Consts.AssemblySystem_Design, typeof(IRootDesigner))]
41 [DefaultEvent("Load")]
42 #if NET_2_0
43 [ClassInterface (ClassInterfaceType.AutoDispatch)]
44 [InitializationEvent ("Load")]
45 [ComVisible (true)]
46 #endif
47 [ToolboxItem(false)]
48 public class Form : ContainerControl {
49 #region Local Variables
50 internal bool closing;
51 FormBorderStyle form_border_style;
52 private bool autoscale;
53 private Size clientsize_set;
54 private Size autoscale_base_size;
55 private bool allow_transparency;
56 private static Icon default_icon;
57 internal bool is_modal;
58 internal FormWindowState window_state;
59 private bool control_box;
60 private bool minimize_box;
61 private bool maximize_box;
62 private bool help_button;
63 private bool show_in_taskbar;
64 private bool topmost;
65 private IButtonControl accept_button;
66 private IButtonControl cancel_button;
67 private DialogResult dialog_result;
68 private FormStartPosition start_position;
69 private Form owner;
70 private Form.ControlCollection owned_forms;
71 private MdiClient mdi_container;
72 internal InternalWindowManager window_manager;
73 private Form mdi_parent;
74 private bool key_preview;
75 private MainMenu menu;
76 private Icon icon;
77 private Size maximum_size;
78 private Size minimum_size;
79 private SizeGripStyle size_grip_style;
80 private Rectangle maximized_bounds;
81 private Rectangle default_maximized_bounds;
82 private double opacity;
83 internal ApplicationContext context;
84 Color transparency_key;
85 internal MenuTracker active_tracker;
86 private bool is_loaded;
87 internal bool is_changing_visible_state;
88 internal bool has_been_visible;
90 #if NET_2_0
91 private MenuStrip main_menu_strip;
92 private bool show_icon;
93 private bool shown_raised; // The shown event is only raised once
94 #endif
95 #endregion // Local Variables
97 #region Private & Internal Methods
98 static Form ()
100 default_icon = Locale.GetResource("mono.ico") as Icon;
103 // warning: this is only hooked up when an mdi container is created.
104 private void ControlAddedHandler (object sender, ControlEventArgs e)
106 if (mdi_container != null) {
107 mdi_container.SendToBack ();
111 // Convenience method for fire BOTH OnClosing and OnFormClosing events
112 // Returns the value of Cancel, so true means the Close was cancelled,
113 // and you shouldn't close the form.
114 internal bool FireClosingEvents (CloseReason reason)
116 CancelEventArgs cea = new CancelEventArgs ();
117 this.OnClosing (cea);
119 #if NET_2_0
120 FormClosingEventArgs fcea = new FormClosingEventArgs (reason, cea.Cancel);
121 this.OnFormClosing (fcea);
122 return fcea.Cancel;
123 #else
124 return cea.Cancel;
125 #endif
128 private void SelectActiveControl ()
130 if (this.IsMdiContainer) {
131 mdi_container.SendFocusToActiveChild ();
132 return;
135 if (this.ActiveControl == null) {
136 bool visible;
138 // This visible hack is to work around CanSelect always being false if one of the parents
139 // is not visible; and we by default create Form invisible...
140 visible = this.is_visible;
141 this.is_visible = true;
143 if (SelectNextControl (this, true, true, true, true) == false) {
144 Select (this);
147 this.is_visible = visible;
148 } else {
149 Select (ActiveControl);
152 #endregion // Private & Internal Methods
154 #region Public Classes
155 public new class ControlCollection : Control.ControlCollection {
156 Form form_owner;
158 public ControlCollection(Form owner) : base(owner) {
159 this.form_owner = owner;
162 public override void Add(Control value) {
163 if (Contains (value))
164 return;
165 AddToList (value);
166 ((Form)value).owner=form_owner;
169 public override void Remove(Control value) {
170 ((Form)value).owner = null;
171 base.Remove (value);
174 #endregion // Public Classes
176 #region Public Constructor & Destructor
177 public Form ()
179 SizeF current_scale = GetAutoScaleSize (DeviceContext, Font);
181 autoscale = true;
182 autoscale_base_size = new Size ((int)current_scale.Width, (int) current_scale.Height);
183 allow_transparency = false;
184 closing = false;
185 is_modal = false;
186 dialog_result = DialogResult.None;
187 start_position = FormStartPosition.WindowsDefaultLocation;
188 form_border_style = FormBorderStyle.Sizable;
189 window_state = FormWindowState.Normal;
190 key_preview = false;
191 opacity = 1D;
192 menu = null;
193 icon = default_icon;
194 minimum_size = Size.Empty;
195 maximum_size = Size.Empty;
196 clientsize_set = Size.Empty;
197 control_box = true;
198 minimize_box = true;
199 maximize_box = true;
200 help_button = false;
201 show_in_taskbar = true;
202 is_visible = false;
203 is_toplevel = true;
204 size_grip_style = SizeGripStyle.Auto;
205 maximized_bounds = Rectangle.Empty;
206 default_maximized_bounds = Rectangle.Empty;
207 owned_forms = new Form.ControlCollection(this);
208 transparency_key = Color.Empty;
210 #if NET_2_0
211 show_icon = true;
212 #endif
214 // FIXME: this should disappear just as soon as the handle creation is done in the right place (here is too soon()
215 UpdateBounds();
218 #endregion // Public Constructor & Destructor
220 #region Public Static Properties
222 public static Form ActiveForm {
223 get {
224 Control active;
226 active = FromHandle(XplatUI.GetActive());
228 if (active != null) {
229 if ( !(active is Form)) {
230 Control parent;
232 parent = active.Parent;
233 while (parent != null) {
234 if (parent is Form) {
235 return (Form)parent;
237 parent = parent.Parent;
239 } else {
240 return (Form)active;
243 return null;
247 #endregion // Public Static Properties
249 #region Public Instance Properties
250 [DefaultValue(null)]
251 public IButtonControl AcceptButton {
252 get {
253 return accept_button;
256 set {
257 accept_button = value;
258 CheckAcceptButton();
262 [Browsable(false)]
263 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
264 public bool AllowTransparency {
265 get {
266 return allow_transparency;
269 set {
270 if (value == allow_transparency) {
271 return;
274 allow_transparency = value;
276 if (value) {
277 if (IsHandleCreated) {
278 if ((XplatUI.SupportsTransparency() & TransparencySupport.Set) != 0) {
279 XplatUI.SetWindowTransparency(Handle, Opacity, TransparencyKey);
281 } else {
282 UpdateStyles(); // Remove the WS_EX_LAYERED style
288 #if NET_2_0
289 [Browsable (false)]
290 [EditorBrowsable (EditorBrowsableState.Never)]
291 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
292 [Obsolete ("This property has been deprecated in favor of AutoScaleMode.")]
293 #else
294 [DefaultValue(true)]
295 #endif
296 [MWFCategory("Layout")]
297 public bool AutoScale {
298 get {
299 return autoscale;
302 set {
303 autoscale = value;
307 #if NET_2_0
308 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
309 [EditorBrowsable(EditorBrowsableState.Never)]
310 #else
311 [EditorBrowsable(EditorBrowsableState.Advanced)]
312 #endif
313 [Localizable(true)]
314 [Browsable(false)]
315 public virtual Size AutoScaleBaseSize {
316 get {
317 return autoscale_base_size;
320 set {
321 autoscale_base_size = value;
325 [Localizable(true)]
326 public override bool AutoScroll {
327 get {
328 return base.AutoScroll;
330 set {
331 base.AutoScroll = value;
335 public override Color BackColor {
336 get {
337 /* we don't let parents override our
338 default background color for forms.
339 this fixes the default color for mdi
340 children. */
341 if (background_color.IsEmpty)
342 return DefaultBackColor;
343 else
344 return background_color;
346 set {
347 base.BackColor = value;
351 [DefaultValue(null)]
352 public IButtonControl CancelButton {
353 get {
354 return cancel_button;
357 set {
358 cancel_button = value;
359 if (cancel_button != null && cancel_button.DialogResult == DialogResult.None)
360 cancel_button.DialogResult = DialogResult.Cancel;
364 // new property so we can change the DesignerSerializationVisibility
365 [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
366 [Localizable(true)]
367 public new Size ClientSize {
368 get { return base.ClientSize; }
369 set { base.ClientSize = value; }
372 [DefaultValue(true)]
373 [MWFCategory("Window Style")]
374 public bool ControlBox {
375 get {
376 return control_box;
379 set {
380 if (control_box != value) {
381 control_box = value;
382 UpdateStyles();
387 [Browsable(false)]
388 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
389 public Rectangle DesktopBounds {
390 get {
391 return new Rectangle(Location, Size);
394 set {
395 Bounds = value;
399 [Browsable(false)]
400 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
401 public Point DesktopLocation {
402 get {
403 return Location;
406 set {
407 Location = value;
411 [Browsable(false)]
412 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
413 public DialogResult DialogResult {
414 get {
415 return dialog_result;
418 set {
419 if (value < DialogResult.None || value > DialogResult.No)
420 throw new InvalidEnumArgumentException ("value", (int) value,
421 typeof (DialogResult));
423 dialog_result = value;
424 closing = (dialog_result != DialogResult.None && is_modal);
428 [DefaultValue(FormBorderStyle.Sizable)]
429 [DispId(-504)]
430 [MWFCategory("Appearance")]
431 public FormBorderStyle FormBorderStyle {
432 get {
433 return form_border_style;
435 set {
436 form_border_style = value;
438 if (window_manager == null) {
439 if (IsHandleCreated) {
440 XplatUI.SetBorderStyle(window.Handle, form_border_style);
442 } else {
443 window_manager.UpdateBorderStyle (value);
446 UpdateStyles();
450 [DefaultValue(false)]
451 [MWFCategory("Window Style")]
452 public bool HelpButton {
453 get {
454 return help_button;
457 set {
458 if (help_button != value) {
459 help_button = value;
460 UpdateStyles();
465 [Localizable(true)]
466 [AmbientValue(null)]
467 [MWFCategory("Window Style")]
468 public Icon Icon {
469 get {
470 return icon;
473 set {
474 if (icon != value) {
475 icon = value;
477 if (IsHandleCreated) {
478 XplatUI.SetIcon(Handle, icon == null ? default_icon : icon);
484 [Browsable(false)]
485 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
486 public bool IsMdiChild {
487 get {
488 return mdi_parent != null;
492 [DefaultValue(false)]
493 [MWFCategory("Window Style")]
494 public bool IsMdiContainer {
495 get {
496 return mdi_container != null;
499 set {
500 if (value && mdi_container == null) {
501 mdi_container = new MdiClient ();
502 Controls.Add(mdi_container);
503 ControlAdded += new ControlEventHandler (ControlAddedHandler);
504 mdi_container.SendToBack ();
505 mdi_container.SetParentText (true);
506 } else if (!value && mdi_container != null) {
507 Controls.Remove(mdi_container);
508 mdi_container = null;
513 [Browsable(false)]
514 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
515 public Form ActiveMdiChild {
516 get {
517 if (!IsMdiContainer)
518 return null;
519 return (Form) mdi_container.ActiveMdiChild;
523 [Browsable(false)]
524 [EditorBrowsable(EditorBrowsableState.Advanced)]
525 public bool IsRestrictedWindow {
526 get {
527 return false;
531 [DefaultValue(false)]
532 public bool KeyPreview {
533 get {
534 return key_preview;
537 set {
538 key_preview = value;
542 #if NET_2_0
543 [DefaultValue (null)]
544 [TypeConverter (typeof (ReferenceConverter))]
545 public MenuStrip MainMenuStrip {
546 get { return this.main_menu_strip; }
547 set {
548 if (this.main_menu_strip != value) {
549 this.main_menu_strip = value;
550 this.main_menu_strip.RefreshMdiItems ();
555 [Browsable (false)]
556 public new Padding Margin {
557 get { return base.Margin; }
558 set { base.Margin = value; }
560 #endif
562 [DefaultValue(true)]
563 [MWFCategory("Window Style")]
564 public bool MaximizeBox {
565 get {
566 return maximize_box;
568 set {
569 if (maximize_box != value) {
570 maximize_box = value;
571 if (IsHandleCreated) {
572 RecreateHandle();
574 UpdateStyles();
579 [DefaultValue("{Width=0, Height=0}")]
580 [Localizable(true)]
581 [RefreshProperties(RefreshProperties.Repaint)]
582 [MWFCategory("Layout")]
583 public
584 #if NET_2_0
585 override
586 #endif
587 Size MaximumSize {
588 get {
589 return maximum_size;
592 set {
593 if (maximum_size != value) {
594 maximum_size = value;
595 OnMaximumSizeChanged(EventArgs.Empty);
596 if (IsHandleCreated) {
597 XplatUI.SetWindowMinMax(Handle, maximized_bounds, minimum_size, maximum_size);
603 [Browsable(false)]
604 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
605 public Form[] MdiChildren {
606 get {
607 if (mdi_container != null)
608 return mdi_container.MdiChildren;
609 else
610 return new Form[0];
614 [Browsable(false)]
615 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
616 public Form MdiParent {
617 get {
618 return mdi_parent;
621 set {
622 if (value != null && !value.IsMdiContainer)
623 throw new ArgumentException ("Form that was specified to be "
624 + "the MdiParent for this form is not an MdiContainer.");
626 if (mdi_parent != null) {
627 mdi_parent.MdiContainer.Controls.Remove (this);
630 if (value != null) {
631 mdi_parent = value;
632 window_manager = new MdiWindowManager (this,
633 mdi_parent.MdiContainer);
634 mdi_parent.MdiContainer.Controls.Add (this);
635 mdi_parent.MdiContainer.Controls.SetChildIndex (this, 0);
637 RecreateHandle ();
639 } else if (mdi_parent != null) {
640 mdi_parent = null;
642 // Create a new window manager
643 window_manager = null;
644 FormBorderStyle = form_border_style;
646 RecreateHandle ();
651 internal MenuTracker ActiveTracker {
652 get { return active_tracker; }
653 set {
654 if (value == active_tracker)
655 return;
657 Capture = value != null;
658 active_tracker = value;
662 internal MdiClient MdiContainer {
663 get { return mdi_container; }
666 internal InternalWindowManager WindowManager {
667 get { return window_manager; }
670 #if NET_2_0
671 [Browsable (false)]
672 [TypeConverter (typeof (ReferenceConverter))]
673 #endif
674 [DefaultValue(null)]
675 [MWFCategory("Window Style")]
676 public MainMenu Menu {
677 get {
678 return menu;
681 set {
682 if (menu != value) {
683 menu = value;
685 if (menu != null && !IsMdiChild) {
686 menu.SetForm (this);
688 if (IsHandleCreated) {
689 XplatUI.SetMenu (window.Handle, menu);
692 if (clientsize_set != Size.Empty) {
693 SetClientSizeCore(clientsize_set.Width, clientsize_set.Height);
694 } else {
695 UpdateBounds (bounds.X, bounds.Y, bounds.Width, bounds.Height, ClientSize.Width, ClientSize.Height -
696 ThemeEngine.Current.CalcMenuBarSize (DeviceContext, menu, ClientSize.Width));
698 } else
699 UpdateBounds ();
704 [Browsable(false)]
705 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
706 [EditorBrowsable(EditorBrowsableState.Advanced)]
707 public MainMenu MergedMenu {
708 get {
709 if (!IsMdiChild || window_manager == null)
710 return null;
711 return ((MdiWindowManager) window_manager).MergedMenu;
715 // This is the menu in display and being used because of merging this can
716 // be different then the menu that is actually assosciated with the form
717 internal MainMenu ActiveMenu {
718 get {
719 if (IsMdiChild)
720 return null;
722 if (IsMdiContainer && mdi_container.Controls.Count > 0 &&
723 ((Form) mdi_container.Controls [0]).WindowState == FormWindowState.Maximized) {
724 MdiWindowManager wm = (MdiWindowManager) ((Form) mdi_container.Controls [0]).WindowManager;
725 return wm.MaximizedMenu;
728 Form amc = ActiveMdiChild;
729 if (amc == null || amc.Menu == null)
730 return menu;
731 return amc.MergedMenu;
735 internal MdiWindowManager ActiveMaximizedMdiChild {
736 get {
737 Form child = ActiveMdiChild;
738 if (child == null)
739 return null;
740 if (child.WindowManager == null || child.window_state != FormWindowState.Maximized)
741 return null;
742 return (MdiWindowManager) child.WindowManager;
746 [DefaultValue(true)]
747 [MWFCategory("Window Style")]
748 public bool MinimizeBox {
749 get {
750 return minimize_box;
752 set {
753 if (minimize_box != value) {
754 minimize_box = value;
755 if (IsHandleCreated) {
756 RecreateHandle();
758 UpdateStyles();
763 #if !NET_2_0
764 [DefaultValue("{Width=0, Height=0}")]
765 #endif
766 [Localizable(true)]
767 [RefreshProperties(RefreshProperties.Repaint)]
768 [MWFCategory("Layout")]
769 public
770 #if NET_2_0
771 override
772 #endif
773 Size MinimumSize {
774 get {
775 return minimum_size;
778 set {
779 if (minimum_size != value) {
780 minimum_size = value;
782 if ((Size.Width < value.Width) || (Size.Height < value.Height)) {
783 Size = new Size(Math.Max(Size.Width, value.Width), Math.Max(Size.Height, value.Height));
787 OnMinimumSizeChanged(EventArgs.Empty);
788 if (IsHandleCreated) {
789 XplatUI.SetWindowMinMax(Handle, maximized_bounds, minimum_size, maximum_size);
795 [Browsable(false)]
796 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
797 public bool Modal {
798 get {
799 return is_modal;
803 [DefaultValue(1D)]
804 [TypeConverter(typeof(OpacityConverter))]
805 [MWFCategory("Window Style")]
806 public double Opacity {
807 get {
808 if (IsHandleCreated) {
809 if ((XplatUI.SupportsTransparency () & TransparencySupport.Get) != 0)
810 return XplatUI.GetWindowTransparency (Handle);
813 return opacity;
816 set {
817 opacity = value;
819 AllowTransparency = true;
821 if (IsHandleCreated) {
822 UpdateStyles();
823 if ((XplatUI.SupportsTransparency () & TransparencySupport.Set) != 0)
824 XplatUI.SetWindowTransparency(Handle, opacity, TransparencyKey);
830 [Browsable(false)]
831 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
832 public Form[] OwnedForms {
833 get {
834 Form[] form_list;
836 form_list = new Form[owned_forms.Count];
838 for (int i=0; i<owned_forms.Count; i++) {
839 form_list[i] = (Form)owned_forms[i];
842 return form_list;
846 [Browsable(false)]
847 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
848 public Form Owner {
849 get {
850 return owner;
853 set {
854 if (owner != value) {
855 if (owner != null) {
856 owner.RemoveOwnedForm(this);
858 owner = value;
859 if (owner != null)
860 owner.AddOwnedForm(this);
861 if (IsHandleCreated) {
862 if (owner != null && owner.IsHandleCreated) {
863 XplatUI.SetTopmost(this.window.Handle, owner.window.Handle, true);
864 } else {
865 XplatUI.SetTopmost(this.window.Handle, IntPtr.Zero, false);
872 #if NET_2_0
873 [DefaultValue (true)]
874 public bool ShowIcon {
875 get { return this.show_icon; }
876 set {
877 if (this.show_icon != value ) {
878 this.show_icon = value;
879 UpdateStyles ();
881 XplatUI.SetIcon (this.Handle, value == true ? this.Icon : null);
882 XplatUI.InvalidateNC (this.Handle);
886 #endif
888 [DefaultValue(true)]
889 [MWFCategory("Window Style")]
890 public bool ShowInTaskbar {
891 get {
892 return show_in_taskbar;
894 set {
895 if (show_in_taskbar != value) {
896 show_in_taskbar = value;
897 if (IsHandleCreated) {
898 RecreateHandle();
900 UpdateStyles();
905 // new property so we can set the DesignerSerializationVisibility
906 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
907 [Localizable(false)]
908 public new Size Size {
909 get { return base.Size; }
910 set { base.Size = value; }
913 [MonoTODO("Trigger something when GripStyle is set")]
914 [DefaultValue(SizeGripStyle.Auto)]
915 [MWFCategory("Window Style")]
916 public SizeGripStyle SizeGripStyle {
917 get {
918 return size_grip_style;
921 set {
922 size_grip_style = value;
926 [DefaultValue(FormStartPosition.WindowsDefaultLocation)]
927 [Localizable(true)]
928 [MWFCategory("Layout")]
929 public FormStartPosition StartPosition {
930 get {
931 return start_position;
934 set {
935 if (start_position == FormStartPosition.WindowsDefaultLocation) { // Only do this if it's not set yet
936 start_position = value;
937 if (IsHandleCreated) {
938 switch(start_position) {
939 case FormStartPosition.CenterParent: {
940 CenterToParent();
941 break;
944 case FormStartPosition.CenterScreen: {
945 CenterToScreen();
946 break;
949 case FormStartPosition.Manual: {
950 Left = CreateParams.X;
951 Top = CreateParams.Y;
952 break;
955 default: {
956 break;
964 // new property so we can set EditorBrowsable to never
965 [Browsable(false)]
966 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
967 [EditorBrowsable(EditorBrowsableState.Never)]
968 public new int TabIndex {
969 get { return base.TabIndex; }
970 set { base.TabIndex = value; }
973 #if NET_2_0
974 [Browsable(false)]
975 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
976 [EditorBrowsable(EditorBrowsableState.Never)]
977 public new bool TabStop {
978 get { return base.TabStop; }
979 set { base.TabStop = value; }
981 #endif
983 [Browsable(false)]
984 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
985 [EditorBrowsable(EditorBrowsableState.Advanced)]
986 public bool TopLevel {
987 get {
988 return GetTopLevel();
991 set {
992 if (!value && IsMdiContainer)
993 throw new ArgumentException ("MDI Container forms must be top level.");
994 SetTopLevel(value);
998 [DefaultValue(false)]
999 [MWFCategory("Window Style")]
1000 public bool TopMost {
1001 get {
1002 return topmost;
1005 set {
1006 if (topmost != value) {
1007 topmost = value;
1008 if (IsHandleCreated)
1009 XplatUI.SetTopmost(window.Handle, owner != null ? owner.window.Handle : IntPtr.Zero, value);
1014 [MWFCategory("Window Style")]
1015 public Color TransparencyKey {
1016 get {
1017 return transparency_key;
1020 set {
1021 transparency_key = value;
1023 AllowTransparency = true;
1024 UpdateStyles();
1025 if ((XplatUI.SupportsTransparency () & TransparencySupport.Set) != 0)
1026 XplatUI.SetWindowTransparency(Handle, Opacity, transparency_key);
1030 [DefaultValue(FormWindowState.Normal)]
1031 [MWFCategory("Layout")]
1032 public FormWindowState WindowState {
1033 get {
1034 if (IsHandleCreated) {
1036 if (window_manager != null)
1037 return window_manager.GetWindowState ();
1039 FormWindowState new_state = XplatUI.GetWindowState(Handle);
1040 if (new_state != (FormWindowState)(-1))
1041 window_state = new_state;
1044 return window_state;
1047 set {
1048 FormWindowState old_state = window_state;
1049 window_state = value;
1050 if (IsHandleCreated) {
1052 if (window_manager != null) {
1053 window_manager.SetWindowState (old_state, value);
1054 return;
1057 XplatUI.SetWindowState(Handle, value);
1062 #endregion // Public Instance Properties
1064 #region Protected Instance Properties
1065 protected override CreateParams CreateParams {
1066 get {
1067 CreateParams cp = new CreateParams ();
1069 cp.Caption = Text;
1070 cp.ClassName = XplatUI.DefaultClassName;
1071 cp.ClassStyle = 0;
1072 cp.Style = 0;
1073 cp.ExStyle = 0;
1074 cp.Param = 0;
1075 cp.Parent = IntPtr.Zero;
1076 cp.menu = ActiveMenu;
1078 if (start_position == FormStartPosition.WindowsDefaultLocation && !IsMdiChild) {
1079 cp.X = unchecked((int)0x80000000);
1080 cp.Y = unchecked((int)0x80000000);
1081 } else {
1082 cp.X = Left;
1083 cp.Y = Top;
1085 cp.Width = Width;
1086 cp.Height = Height;
1088 cp.Style = (int)(WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS);
1090 if (IsMdiChild) {
1091 cp.Style |= (int)(WindowStyles.WS_CHILD | WindowStyles.WS_CAPTION);
1092 if (Parent != null) {
1093 cp.Parent = Parent.Handle;
1096 cp.ExStyle |= (int) (WindowExStyles.WS_EX_WINDOWEDGE | WindowExStyles.WS_EX_MDICHILD);
1098 switch (FormBorderStyle) {
1099 case FormBorderStyle.None:
1100 break;
1101 case FormBorderStyle.FixedToolWindow:
1102 case FormBorderStyle.SizableToolWindow:
1103 cp.ExStyle |= (int) WindowExStyles.WS_EX_TOOLWINDOW;
1104 goto default;
1105 default:
1106 cp.Style |= (int) WindowStyles.WS_OVERLAPPEDWINDOW;
1107 break;
1110 } else {
1111 switch (FormBorderStyle) {
1112 case FormBorderStyle.Fixed3D: {
1113 cp.Style |= (int)(WindowStyles.WS_CAPTION | WindowStyles.WS_BORDER);
1114 cp.ExStyle |= (int)WindowExStyles.WS_EX_CLIENTEDGE;
1115 break;
1118 case FormBorderStyle.FixedDialog: {
1119 cp.Style |= (int)(WindowStyles.WS_CAPTION | WindowStyles.WS_BORDER);
1120 cp.ExStyle |= (int)(WindowExStyles.WS_EX_DLGMODALFRAME | WindowExStyles.WS_EX_CONTROLPARENT);
1121 break;
1124 case FormBorderStyle.FixedSingle: {
1125 cp.Style |= (int)(WindowStyles.WS_CAPTION | WindowStyles.WS_BORDER);
1126 break;
1129 case FormBorderStyle.FixedToolWindow: {
1130 cp.Style |= (int)(WindowStyles.WS_CAPTION | WindowStyles.WS_BORDER);
1131 cp.ExStyle |= (int)(WindowExStyles.WS_EX_TOOLWINDOW);
1132 break;
1135 case FormBorderStyle.Sizable: {
1136 cp.Style |= (int)(WindowStyles.WS_BORDER | WindowStyles.WS_THICKFRAME | WindowStyles.WS_CAPTION);
1137 break;
1140 case FormBorderStyle.SizableToolWindow: {
1141 cp.Style |= (int)(WindowStyles.WS_BORDER | WindowStyles.WS_THICKFRAME | WindowStyles.WS_CAPTION);
1142 cp.ExStyle |= (int)(WindowExStyles.WS_EX_TOOLWINDOW);
1143 break;
1146 case FormBorderStyle.None: {
1147 break;
1152 switch(window_state) {
1153 case FormWindowState.Maximized: {
1154 cp.Style |= (int)WindowStyles.WS_MAXIMIZE;
1155 break;
1158 case FormWindowState.Minimized: {
1159 cp.Style |= (int)WindowStyles.WS_MINIMIZE;
1160 break;
1164 if (TopMost) {
1165 cp.ExStyle |= (int) WindowExStyles.WS_EX_TOPMOST;
1168 if (ShowInTaskbar) {
1169 cp.ExStyle |= (int)WindowExStyles.WS_EX_APPWINDOW;
1172 if (MaximizeBox) {
1173 cp.Style |= (int)WindowStyles.WS_MAXIMIZEBOX;
1176 if (MinimizeBox) {
1177 cp.Style |= (int)WindowStyles.WS_MINIMIZEBOX;
1180 if (ControlBox) {
1181 cp.Style |= (int)WindowStyles.WS_SYSMENU;
1184 #if NET_2_0
1185 if (!this.show_icon) {
1186 cp.ExStyle |= (int)WindowExStyles.WS_EX_DLGMODALFRAME;
1188 #endif
1190 if (HelpButton && !MaximizeBox && !MinimizeBox) {
1191 cp.ExStyle |= (int)WindowExStyles.WS_EX_CONTEXTHELP;
1194 if (Visible)
1195 cp.Style |= (int)WindowStyles.WS_VISIBLE;
1197 if (opacity < 1.0 || TransparencyKey != Color.Empty) {
1198 cp.ExStyle |= (int)WindowExStyles.WS_EX_LAYERED;
1201 if (!is_enabled && context == null) {
1202 cp.Style |= (int)(WindowStyles.WS_DISABLED);
1205 return cp;
1209 protected override ImeMode DefaultImeMode {
1210 get {
1211 return ImeMode.NoControl;
1215 protected override Size DefaultSize {
1216 get {
1217 return new Size (300, 300);
1221 protected Rectangle MaximizedBounds {
1222 get {
1223 if (maximized_bounds != Rectangle.Empty) {
1224 return maximized_bounds;
1226 return default_maximized_bounds;
1229 set {
1230 maximized_bounds = value;
1231 OnMaximizedBoundsChanged(EventArgs.Empty);
1232 if (IsHandleCreated) {
1233 XplatUI.SetWindowMinMax(Handle, maximized_bounds, minimum_size, maximum_size);
1237 #endregion // Protected Instance Properties
1239 #region Public Static Methods
1240 #if NET_2_0
1241 [EditorBrowsable(EditorBrowsableState.Never)]
1242 [Obsolete ("This method has been deprecated. Use AutoScaleDimensions instead")]
1243 #else
1244 [EditorBrowsable(EditorBrowsableState.Advanced)]
1245 #endif
1246 public static SizeF GetAutoScaleSize (Font font)
1248 return XplatUI.GetAutoScaleSize(font);
1251 #endregion // Public Static Methods
1253 #region Public Instance Methods
1254 internal SizeF GetAutoScaleSize (Graphics g, Font font)
1257 // The following constants come from the dotnet mailing list
1258 // discussion: http://discuss.develop.com/archives/wa.exe?A2=ind0203A&L=DOTNET&P=R3655
1260 // The magic number is "Its almost the length
1261 // of the string with a smattering added in
1262 // for compat with earlier code".
1265 string magic_string = "The quick brown fox jumped over the lazy dog.";
1266 double magic_number = 44.549996948242189;
1267 float width = (float) (g.MeasureString (magic_string, font).Width / magic_number);
1269 return new SizeF (width, font.Height);
1272 public void Activate ()
1274 Form active;
1276 // The docs say activate only activates if our app is already active
1277 if (IsHandleCreated) {
1278 if (IsMdiChild) {
1279 MdiParent.ActivateMdiChild (this);
1280 } else if (IsMdiContainer) {
1281 mdi_container.SendFocusToActiveChild ();
1282 } else {
1283 active = ActiveForm;
1284 if ((active != null) && (this != active)) {
1285 XplatUI.Activate(window.Handle);
1291 public void AddOwnedForm(Form ownedForm) {
1292 if (!owned_forms.Contains(ownedForm)) {
1293 owned_forms.Add(ownedForm);
1295 ownedForm.Owner = this;
1298 public void Close () {
1299 if (IsDisposed)
1300 return;
1302 if (!is_visible)
1303 return;
1305 XplatUI.SendMessage(this.Handle, Msg.WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
1308 public void LayoutMdi(MdiLayout value) {
1309 if (mdi_container != null) {
1310 mdi_container.LayoutMdi(value);
1314 public void RemoveOwnedForm(Form ownedForm) {
1315 owned_forms.Remove(ownedForm);
1318 public void SetDesktopBounds(int x, int y, int width, int height) {
1319 DesktopBounds = new Rectangle(x, y, width, height);
1322 public void SetDesktopLocation(int x, int y) {
1323 DesktopLocation = new Point(x, y);
1326 #if NET_2_0
1327 public void Show (IWin32Window owner)
1329 if (owner == null)
1330 this.Owner = null;
1331 else
1332 this.Owner = Control.FromHandle (owner.Handle).TopLevelControl as Form;
1334 if (owner == this)
1335 throw new InvalidOperationException ("The 'owner' cannot be the form being shown.");
1337 base.Show ();
1339 #endif
1341 public DialogResult ShowDialog() {
1342 return ShowDialog(this.owner);
1345 public DialogResult ShowDialog(IWin32Window ownerWin32) {
1346 Rectangle area;
1347 bool confined;
1348 IntPtr capture_window;
1350 owner = null;
1352 if (ownerWin32 != null) {
1353 Control c = Control.FromHandle (ownerWin32.Handle);
1354 if (c != null)
1355 owner = c.TopLevelControl as Form;
1358 if (owner == this) {
1359 throw new InvalidOperationException("The 'ownerWin32' cannot be the form being shown.");
1362 if (is_modal) {
1363 throw new InvalidOperationException("The form is already displayed as a modal dialog.");
1366 if (Visible) {
1367 throw new InvalidOperationException("Already visible forms cannot be displayed as a modal dialog. Set the Visible property to 'false' prior to calling Form.ShowDialog.");
1370 if (!Enabled) {
1371 throw new InvalidOperationException("Cannot display a disabled form as modal dialog.");
1374 if (TopLevelControl != this) {
1375 throw new InvalidOperationException("Can only display TopLevel forms as modal dialog.");
1378 #if broken
1379 // Can't do this, will screw us in the modal loop
1380 form_parent_window.Parent = this.owner;
1381 #endif
1383 // Release any captures
1384 XplatUI.GrabInfo(out capture_window, out confined, out area);
1385 if (capture_window != IntPtr.Zero) {
1386 XplatUI.UngrabWindow(capture_window);
1389 #if not
1390 // Commented out; we instead let the Visible=true inside the runloop create the control
1391 // otherwise setting DialogResult inside any of the events that are triggered by the
1392 // create will not actually cause the form to not be displayed.
1393 // Leaving this comment here in case there was an actual purpose to creating the control
1394 // in here.
1395 if (!IsHandleCreated) {
1396 CreateControl();
1398 #endif
1400 Application.RunLoop(true, new ApplicationContext(this));
1402 if (owner != null) {
1403 // Cannot use Activate(), it has a check for the current active window...
1404 XplatUI.Activate(owner.window.Handle);
1407 if (DialogResult != DialogResult.None) {
1408 return DialogResult;
1410 DialogResult = DialogResult.Cancel;
1411 return DialogResult.Cancel;
1414 public override string ToString() {
1415 return GetType().FullName.ToString() + ", Text: " + Text;
1417 #endregion // Public Instance Methods
1419 #region Protected Instance Methods
1420 protected void ActivateMdiChild(Form form) {
1421 if (!IsMdiContainer)
1422 return;
1423 mdi_container.ActivateChild (form);
1424 OnMdiChildActivate(EventArgs.Empty);
1427 [EditorBrowsable(EditorBrowsableState.Advanced)]
1428 protected override void AdjustFormScrollbars(bool displayScrollbars) {
1429 base.AdjustFormScrollbars (displayScrollbars);
1432 #if NET_2_0
1433 [EditorBrowsable(EditorBrowsableState.Never)]
1434 [Obsolete ("This method has been deprecated")] // XXX what to use instead?
1435 #else
1436 [EditorBrowsable(EditorBrowsableState.Advanced)]
1437 #endif
1438 protected void ApplyAutoScaling()
1440 SizeF current_size_f = GetAutoScaleSize (DeviceContext, Font);
1441 Size current_size = new Size ((int) current_size_f.Width, (int) current_size_f.Height);
1442 float dx;
1443 float dy;
1445 if (current_size == autoscale_base_size)
1446 return;
1448 if (Environment.GetEnvironmentVariable ("MONO_MWF_SCALING") == "disable"){
1449 return;
1453 // I tried applying the Fudge height factor from:
1454 // http://blogs.msdn.com/mharsh/archive/2004/01/25/62621.aspx
1455 // but it makes things larger without looking better.
1457 if (current_size_f.Width != AutoScaleBaseSize.Width) {
1458 dx = current_size_f.Width / AutoScaleBaseSize.Width + 0.08f;
1459 } else {
1460 dx = 1;
1463 if (current_size_f.Height != AutoScaleBaseSize.Height) {
1464 dy = current_size_f.Height / AutoScaleBaseSize.Height + 0.08f;
1465 } else {
1466 dy = 1;
1469 Scale (dx, dy);
1471 AutoScaleBaseSize = current_size;
1474 protected void CenterToParent() {
1475 Control ctl;
1476 int w;
1477 int h;
1479 if (Width > 0) {
1480 w = Width;
1481 } else {
1482 w = DefaultSize.Width;
1485 if (Height > 0) {
1486 h = Height;
1487 } else {
1488 h = DefaultSize.Height;
1491 ctl = null;
1492 if (Parent != null) {
1493 ctl = Parent;
1494 } else if (owner != null) {
1495 ctl = owner;
1498 if (owner != null) {
1499 this.Location = new Point(ctl.Left + ctl.Width / 2 - w /2, ctl.Top + ctl.Height / 2 - h / 2);
1503 protected void CenterToScreen() {
1504 Size DisplaySize;
1505 int w;
1506 int h;
1508 if (Width > 0) {
1509 w = Width;
1510 } else {
1511 w = DefaultSize.Width;
1514 if (Height > 0) {
1515 h = Height;
1516 } else {
1517 h = DefaultSize.Height;
1520 XplatUI.GetDisplaySize(out DisplaySize);
1521 this.Location = new Point(DisplaySize.Width / 2 - w / 2, DisplaySize.Height / 2 - h / 2);
1524 [EditorBrowsable(EditorBrowsableState.Advanced)]
1525 protected override Control.ControlCollection CreateControlsInstance() {
1526 return base.CreateControlsInstance ();
1529 [EditorBrowsable(EditorBrowsableState.Advanced)]
1530 protected override void CreateHandle() {
1531 base.CreateHandle ();
1533 Application.AddForm (this);
1535 UpdateBounds();
1537 if ((XplatUI.SupportsTransparency() & TransparencySupport.Set) != 0) {
1538 if (allow_transparency) {
1539 XplatUI.SetWindowTransparency(Handle, Opacity, TransparencyKey);
1543 XplatUI.SetWindowMinMax(window.Handle, maximized_bounds, minimum_size, maximum_size);
1544 if ((FormBorderStyle != FormBorderStyle.FixedDialog) && (icon != null)) {
1545 XplatUI.SetIcon(window.Handle, icon);
1548 if ((owner != null) && (owner.IsHandleCreated)) {
1549 XplatUI.SetTopmost(window.Handle, owner.window.Handle, true);
1552 for (int i = 0; i < owned_forms.Count; i++) {
1553 if (owned_forms[i].IsHandleCreated)
1554 XplatUI.SetTopmost(owned_forms[i].window.Handle, window.Handle, true);
1557 if (window_manager != null) {
1558 if (window_state != FormWindowState.Normal) {
1559 window_manager.SetWindowState (FormWindowState.Normal, window_state);
1561 XplatUI.RequestNCRecalc (window.Handle);
1566 [EditorBrowsable(EditorBrowsableState.Advanced)]
1567 protected override void DefWndProc(ref Message m) {
1568 base.DefWndProc (ref m);
1571 protected override void Dispose(bool disposing)
1573 for (int i = 0; i < owned_forms.Count; i++)
1574 ((Form)owned_forms[i]).Owner = null;
1576 owned_forms.Clear ();
1578 base.Dispose (disposing);
1580 Application.RemoveForm (this);
1583 [EditorBrowsable(EditorBrowsableState.Advanced)]
1584 protected virtual void OnActivated(EventArgs e)
1586 EventHandler eh = (EventHandler)(Events [ActivatedEvent]);
1587 if (eh != null)
1588 eh (this, e);
1591 [EditorBrowsable(EditorBrowsableState.Advanced)]
1592 protected virtual void OnClosed(EventArgs e) {
1593 EventHandler eh = (EventHandler)(Events [ClosedEvent]);
1594 if (eh != null)
1595 eh (this, e);
1598 // Consider calling FireClosingEvents instead of calling this directly.
1599 [EditorBrowsable (EditorBrowsableState.Advanced)]
1600 protected virtual void OnClosing(System.ComponentModel.CancelEventArgs e) {
1601 CancelEventHandler eh = (CancelEventHandler)(Events [ClosingEvent]);
1602 if (eh != null)
1603 eh (this, e);
1606 [EditorBrowsable(EditorBrowsableState.Advanced)]
1607 protected override void OnCreateControl() {
1608 base.OnCreateControl ();
1610 if (menu != null) {
1611 XplatUI.SetMenu(window.Handle, menu);
1614 OnLoad(EventArgs.Empty);
1616 // Send initial location
1617 OnLocationChanged(EventArgs.Empty);
1619 if (IsMdiContainer) {
1620 mdi_container.LayoutMdi (MdiLayout.Cascade);
1624 [EditorBrowsable(EditorBrowsableState.Advanced)]
1625 protected virtual void OnDeactivate(EventArgs e) {
1626 EventHandler eh = (EventHandler)(Events [DeactivateEvent]);
1627 if (eh != null)
1628 eh (this, e);
1631 [EditorBrowsable(EditorBrowsableState.Advanced)]
1632 protected override void OnFontChanged(EventArgs e) {
1633 base.OnFontChanged (e);
1636 [EditorBrowsable(EditorBrowsableState.Advanced)]
1637 protected override void OnHandleCreated(EventArgs e) {
1638 XplatUI.SetBorderStyle(window.Handle, form_border_style);
1639 base.OnHandleCreated (e);
1642 [EditorBrowsable(EditorBrowsableState.Advanced)]
1643 protected override void OnHandleDestroyed(EventArgs e) {
1644 base.OnHandleDestroyed (e);
1647 [EditorBrowsable(EditorBrowsableState.Advanced)]
1648 protected virtual void OnInputLanguageChanged(InputLanguageChangedEventArgs e) {
1649 InputLanguageChangedEventHandler eh = (InputLanguageChangedEventHandler)(Events [InputLanguageChangedEvent]);
1650 if (eh != null)
1651 eh (this, e);
1654 [EditorBrowsable(EditorBrowsableState.Advanced)]
1655 protected virtual void OnInputLanguageChanging(InputLanguageChangingEventArgs e) {
1656 InputLanguageChangingEventHandler eh = (InputLanguageChangingEventHandler)(Events [InputLanguageChangingEvent]);
1657 if (eh != null)
1658 eh (this, e);
1661 [EditorBrowsable(EditorBrowsableState.Advanced)]
1662 protected virtual void OnLoad(EventArgs e) {
1663 if (AutoScale){
1664 ApplyAutoScaling ();
1665 AutoScale = false;
1668 EventHandler eh = (EventHandler)(Events [LoadEvent]);
1669 if (eh != null)
1670 eh (this, e);
1672 if (!IsMdiChild) {
1673 switch (StartPosition) {
1674 case FormStartPosition.CenterScreen:
1675 this.CenterToScreen();
1676 break;
1677 case FormStartPosition.CenterParent:
1678 this.CenterToParent ();
1679 break;
1680 case FormStartPosition.Manual:
1681 Left = CreateParams.X;
1682 Top = CreateParams.Y;
1683 break;
1686 is_loaded = true;
1689 [EditorBrowsable(EditorBrowsableState.Advanced)]
1690 protected virtual void OnMaximizedBoundsChanged(EventArgs e) {
1691 EventHandler eh = (EventHandler)(Events [MaximizedBoundsChangedEvent]);
1692 if (eh != null)
1693 eh (this, e);
1696 [EditorBrowsable(EditorBrowsableState.Advanced)]
1697 protected virtual void OnMaximumSizeChanged(EventArgs e) {
1698 EventHandler eh = (EventHandler)(Events [MaximumSizeChangedEvent]);
1699 if (eh != null)
1700 eh (this, e);
1703 [EditorBrowsable(EditorBrowsableState.Advanced)]
1704 protected virtual void OnMdiChildActivate(EventArgs e) {
1705 EventHandler eh = (EventHandler)(Events [MdiChildActivateEvent]);
1706 if (eh != null)
1707 eh (this, e);
1710 [EditorBrowsable(EditorBrowsableState.Advanced)]
1711 protected virtual void OnMenuComplete(EventArgs e) {
1712 EventHandler eh = (EventHandler)(Events [MenuCompleteEvent]);
1713 if (eh != null)
1714 eh (this, e);
1717 [EditorBrowsable(EditorBrowsableState.Advanced)]
1718 protected virtual void OnMenuStart(EventArgs e) {
1719 EventHandler eh = (EventHandler)(Events [MenuStartEvent]);
1720 if (eh != null)
1721 eh (this, e);
1724 [EditorBrowsable(EditorBrowsableState.Advanced)]
1725 protected virtual void OnMinimumSizeChanged(EventArgs e) {
1726 EventHandler eh = (EventHandler)(Events [MinimumSizeChangedEvent]);
1727 if (eh != null)
1728 eh (this, e);
1731 [EditorBrowsable(EditorBrowsableState.Advanced)]
1732 protected override void OnPaint (PaintEventArgs pevent) {
1733 base.OnPaint (pevent);
1736 [EditorBrowsable(EditorBrowsableState.Advanced)]
1737 protected override void OnResize(EventArgs e) {
1738 base.OnResize(e);
1740 if (this.IsMdiChild && ParentForm != null) {
1741 ParentForm.PerformLayout();
1742 ParentForm.Size = ParentForm.Size;
1746 [EditorBrowsable(EditorBrowsableState.Advanced)]
1747 protected override void OnStyleChanged(EventArgs e) {
1748 base.OnStyleChanged (e);
1751 [EditorBrowsable(EditorBrowsableState.Advanced)]
1752 protected override void OnTextChanged(EventArgs e) {
1753 base.OnTextChanged (e);
1755 if (mdi_container != null)
1756 mdi_container.SetParentText(true);
1759 [EditorBrowsable(EditorBrowsableState.Advanced)]
1760 protected override void OnVisibleChanged(EventArgs e) {
1761 base.OnVisibleChanged (e);
1763 if (Visible) {
1764 if (window_manager != null)
1765 window_manager.SetWindowState (WindowState, WindowState);
1769 protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
1770 if (base.ProcessCmdKey (ref msg, keyData)) {
1771 return true;
1774 // Give our menu a shot
1775 if (ActiveMenu != null) {
1776 return ActiveMenu.ProcessCmdKey(ref msg, keyData);
1779 if (IsMdiChild) {
1780 switch (keyData)
1782 case Keys.Control | Keys.F4:
1783 case Keys.Control | Keys.Shift | Keys.F4:
1784 Close ();
1785 return true;
1786 case Keys.Control | Keys.Tab:
1787 case Keys.Control | Keys.F6:
1788 MdiParent.MdiContainer.ActivateNextChild ();
1789 return true;
1790 case Keys.Control | Keys.Shift | Keys.Tab:
1791 case Keys.Control | Keys.Shift | Keys.F6:
1792 MdiParent.MdiContainer.ActivatePreviousChild ();
1793 return true;
1797 return false;
1800 // LAMESPEC - Not documented that Form overrides ProcessDialogChar; class-status showed
1801 [EditorBrowsable (EditorBrowsableState.Advanced)]
1802 protected override bool ProcessDialogChar(char charCode) {
1803 return base.ProcessDialogChar (charCode);
1806 protected override bool ProcessDialogKey(Keys keyData) {
1807 if ((keyData & Keys.Modifiers) == 0) {
1808 if (keyData == Keys.Enter) {
1809 IntPtr window = XplatUI.GetFocus ();
1810 Control c = Control.FromHandle (window);
1811 if (c is Button && c.FindForm () == this) {
1812 ((Button)c).PerformClick ();
1813 return true;
1815 else if (accept_button != null) {
1816 accept_button.PerformClick();
1817 return true;
1819 } else if (keyData == Keys.Escape && cancel_button != null) {
1820 cancel_button.PerformClick();
1821 return true;
1824 return base.ProcessDialogKey(keyData);
1827 protected override bool ProcessKeyPreview(ref Message msg) {
1828 if (key_preview) {
1829 if (ProcessKeyEventArgs(ref msg)) {
1830 return true;
1833 return base.ProcessKeyPreview (ref msg);
1836 protected override bool ProcessTabKey(bool forward) {
1837 return SelectNextControl(ActiveControl, forward, true, true, true);
1840 #if NET_2_0
1841 [EditorBrowsable(EditorBrowsableState.Never)]
1842 #else
1843 [EditorBrowsable(EditorBrowsableState.Advanced)]
1844 #endif
1845 protected override void ScaleCore(float dx, float dy) {
1846 try {
1847 SuspendLayout();
1849 // We can't scale max or min windows
1850 if (WindowState == FormWindowState.Normal) {
1851 // We cannot call base since base also adjusts X/Y, but
1852 // a form is toplevel and doesn't move
1853 Size size;
1855 size = ClientSize;
1856 if (!GetStyle(ControlStyles.FixedWidth)) {
1857 size.Width = (int)(size.Width * dx);
1860 if (!GetStyle(ControlStyles.FixedHeight)) {
1861 size.Height = (int)(size.Height * dy);
1864 ClientSize = size;
1867 /* Now scale our children */
1868 Control [] controls = Controls.GetAllControls ();
1869 for (int i=0; i < controls.Length; i++) {
1870 controls[i].Scale(dx, dy);
1874 finally {
1875 ResumeLayout();
1879 protected override void Select(bool directed, bool forward) {
1880 Form parent;
1882 if (directed) {
1883 base.SelectNextControl(null, forward, true, true, true);
1886 parent = this.ParentForm;
1887 if (parent != null) {
1888 parent.ActiveControl = this;
1891 Activate();
1894 [EditorBrowsable(EditorBrowsableState.Advanced)]
1895 protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
1896 base.SetBoundsCore (x, y, width, height, specified);
1899 [EditorBrowsable(EditorBrowsableState.Advanced)]
1900 protected override void SetClientSizeCore(int x, int y) {
1901 if ((minimum_size.Width != 0) && (x < minimum_size.Width)) {
1902 x = minimum_size.Width;
1903 } else if ((maximum_size.Width != 0) && (x > maximum_size.Width)) {
1904 x = maximum_size.Width;
1907 if ((minimum_size.Height != 0) && (y < minimum_size.Height)) {
1908 y = minimum_size.Height;
1909 } else if ((maximum_size.Height != 0) && (y > maximum_size.Height)) {
1910 y = maximum_size.Height;
1913 Rectangle ClientRect = new Rectangle(0, 0, x, y);
1914 Rectangle WindowRect;
1915 CreateParams cp = this.CreateParams;
1917 clientsize_set = new Size(x, y);
1919 if (XplatUI.CalculateWindowRect(ref ClientRect, cp.Style, cp.ExStyle, cp.menu, out WindowRect)) {
1920 SetBounds(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
1924 [EditorBrowsable(EditorBrowsableState.Advanced)]
1925 protected override void SetVisibleCore(bool value) {
1926 is_changing_visible_state = true;
1927 has_been_visible = value || has_been_visible;
1928 base.SetVisibleCore (value);
1929 is_changing_visible_state = false;
1931 #if NET_2_0
1932 // Shown event is only called once, the first time the form is made visible
1933 if (value && !shown_raised) {
1934 this.OnShown (EventArgs.Empty);
1935 shown_raised = true;
1937 #endif
1940 protected override void UpdateDefaultButton() {
1941 base.UpdateDefaultButton ();
1944 [EditorBrowsable(EditorBrowsableState.Advanced)]
1945 protected override void WndProc(ref Message m) {
1947 if (window_manager != null && window_manager.HandleMessage (ref m)) {
1948 return;
1951 switch((Msg)m.Msg) {
1952 case Msg.WM_DESTROY: {
1953 base.WndProc(ref m);
1954 if (!RecreatingHandle) {
1955 this.closing = true;
1957 return;
1960 case Msg.WM_CLOSE_INTERNAL: {
1961 DestroyHandle();
1962 break;
1965 case Msg.WM_CLOSE: {
1966 Form act = Form.ActiveForm;
1967 if (act != null && act != this && act.Modal == true) {
1968 return;
1971 if (mdi_container != null) {
1972 foreach (Form mdi_child in mdi_container.MdiChildren) {
1973 mdi_child.FireClosingEvents (CloseReason.MdiFormClosing);
1977 if (!is_modal) {
1978 if (!FireClosingEvents (CloseReason.UserClosing)) {
1979 OnClosed (EventArgs.Empty);
1980 #if NET_2_0
1981 OnFormClosed (new FormClosedEventArgs (CloseReason.UserClosing));
1982 #endif
1983 closing = true;
1984 Dispose ();
1986 else {
1987 closing = false;
1989 } else {
1990 if (FireClosingEvents (CloseReason.UserClosing)) {
1991 DialogResult = DialogResult.None;
1992 closing = false;
1994 else {
1995 OnClosed (EventArgs.Empty);
1996 #if NET_2_0
1997 OnFormClosed (new FormClosedEventArgs (CloseReason.UserClosing));
1998 #endif
1999 closing = true;
2000 Hide ();
2004 return;
2007 case Msg.WM_WINDOWPOSCHANGED: {
2008 if (WindowState != FormWindowState.Minimized) {
2009 base.WndProc(ref m);
2011 return;
2014 #if NET_2_0
2015 case Msg.WM_SYSCOMMAND: {
2016 // Let *Strips know the app's title bar was clicked
2017 if (XplatUI.IsEnabled (Handle))
2018 ToolStripManager.FireAppClicked ();
2020 base.WndProc(ref m);
2021 break;
2023 #endif
2025 case Msg.WM_ACTIVATE: {
2026 if (m.WParam != (IntPtr)WindowActiveFlags.WA_INACTIVE) {
2027 if (is_loaded) {
2028 SelectActiveControl ();
2030 if (ActiveControl != null && !ActiveControl.Focused)
2031 SendControlFocus (ActiveControl);
2034 OnActivated(EventArgs.Empty);
2035 } else {
2036 OnDeactivate(EventArgs.Empty);
2038 return;
2041 case Msg.WM_KILLFOCUS: {
2042 base.WndProc(ref m);
2043 return;
2046 case Msg.WM_SETFOCUS: {
2047 if (ActiveControl != null && ActiveControl != this) {
2048 ActiveControl.Focus();
2049 return; // FIXME - do we need to run base.WndProc, even though we just changed focus?
2051 if (IsMdiContainer) {
2052 mdi_container.SendFocusToActiveChild ();
2053 return;
2055 base.WndProc(ref m);
2056 return;
2059 // Menu drawing
2060 case Msg.WM_NCLBUTTONDOWN: {
2061 if (XplatUI.IsEnabled (Handle) && ActiveMenu != null) {
2062 ActiveMenu.OnMouseDown(this, new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()), mouse_clicks, Control.MousePosition.X, Control.MousePosition.Y, 0));
2065 if (ActiveMaximizedMdiChild != null) {
2066 if (ActiveMaximizedMdiChild.HandleMenuMouseDown (ActiveMenu,
2067 LowOrder ((int) m.LParam.ToInt32 ()),
2068 HighOrder ((int) m.LParam.ToInt32 ()))) {
2069 // Don't let base process this message, otherwise we won't
2070 // get a WM_NCLBUTTONUP.
2071 return;
2074 base.WndProc(ref m);
2075 return;
2077 case Msg.WM_NCLBUTTONUP: {
2078 if (ActiveMaximizedMdiChild != null) {
2079 ActiveMaximizedMdiChild.HandleMenuMouseUp (ActiveMenu,
2080 LowOrder ((int)m.LParam.ToInt32 ()),
2081 HighOrder ((int)m.LParam.ToInt32 ()));
2083 base.WndProc (ref m);
2084 return;
2087 case Msg.WM_NCMOUSELEAVE: {
2088 if (ActiveMaximizedMdiChild != null) {
2089 ActiveMaximizedMdiChild.HandleMenuMouseLeave(ActiveMenu,
2090 LowOrder((int)m.LParam.ToInt32()),
2091 HighOrder((int)m.LParam.ToInt32()));
2093 base.WndProc(ref m);
2094 return;
2097 case Msg.WM_NCMOUSEMOVE: {
2098 if (XplatUI.IsEnabled (Handle) && ActiveMenu != null) {
2099 ActiveMenu.OnMouseMove(this, new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()), mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()), 0));
2102 if (ActiveMaximizedMdiChild != null) {
2103 XplatUI.RequestAdditionalWM_NCMessages (Handle, false, true);
2104 ActiveMaximizedMdiChild.HandleMenuMouseMove (ActiveMenu,
2105 LowOrder ((int)m.LParam.ToInt32 ()),
2106 HighOrder ((int)m.LParam.ToInt32 ()));
2108 base.WndProc(ref m);
2109 return;
2112 case Msg.WM_NCPAINT: {
2113 if (ActiveMenu != null) {
2114 PaintEventArgs pe;
2115 Point pnt;
2117 pe = XplatUI.PaintEventStart(Handle, false);
2118 pnt = XplatUI.GetMenuOrigin(window.Handle);
2120 // The entire menu has to be in the clip rectangle because the
2121 // control buttons are right-aligned and otherwise they would
2122 // stay painted when the window gets resized.
2123 Rectangle clip = new Rectangle (pnt.X, pnt.Y, ClientSize.Width, 0);
2124 clip = Rectangle.Union(clip, pe.ClipRectangle);
2125 pe.SetClip(clip);
2126 pe.Graphics.SetClip(clip);
2128 ActiveMenu.Draw (pe, new Rectangle (pnt.X, pnt.Y, ClientSize.Width, 0));
2130 if (ActiveMaximizedMdiChild != null) {
2131 ActiveMaximizedMdiChild.DrawMaximizedButtons (ActiveMenu, pe);
2134 XplatUI.PaintEventEnd(Handle, false);
2137 base.WndProc(ref m);
2138 return;
2141 case Msg.WM_NCCALCSIZE: {
2142 XplatUIWin32.NCCALCSIZE_PARAMS ncp;
2144 if ((ActiveMenu != null) && (m.WParam == (IntPtr)1)) {
2145 ncp = (XplatUIWin32.NCCALCSIZE_PARAMS)Marshal.PtrToStructure(m.LParam, typeof(XplatUIWin32.NCCALCSIZE_PARAMS));
2147 // Adjust for menu
2148 ncp.rgrc1.top += ThemeEngine.Current.CalcMenuBarSize (DeviceContext, ActiveMenu, ClientSize.Width);
2149 Marshal.StructureToPtr(ncp, m.LParam, true);
2151 DefWndProc(ref m);
2152 break;
2155 case Msg.WM_MOUSEMOVE: {
2156 if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
2157 MouseEventArgs args;
2159 args = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
2160 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()), 0);
2161 active_tracker.OnMotion(new MouseEventArgs (args.Button, args.Clicks, Control.MousePosition.X, Control.MousePosition.Y, args.Delta));
2162 break;
2164 base.WndProc(ref m);
2165 break;
2168 case Msg.WM_LBUTTONDOWN:
2169 case Msg.WM_MBUTTONDOWN:
2170 case Msg.WM_RBUTTONDOWN: {
2171 if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
2172 MouseEventArgs args;
2174 args = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
2175 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()), 0);
2176 active_tracker.OnMouseDown(new MouseEventArgs (args.Button, args.Clicks, Control.MousePosition.X, Control.MousePosition.Y, args.Delta));
2177 return;
2179 base.WndProc(ref m);
2180 return;
2183 case Msg.WM_LBUTTONUP:
2184 case Msg.WM_MBUTTONUP:
2185 case Msg.WM_RBUTTONUP: {
2186 if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
2187 MouseEventArgs args;
2188 MouseButtons mb = FromParamToMouseButtons ((int) m.WParam.ToInt32());
2190 // We add in the button that was released (not sent in WParam)
2191 switch((Msg)m.Msg) {
2192 case Msg.WM_LBUTTONUP:
2193 mb |= MouseButtons.Left;
2194 break;
2195 case Msg.WM_MBUTTONUP:
2196 mb |= MouseButtons.Middle;
2197 break;
2198 case Msg.WM_RBUTTONUP:
2199 mb |= MouseButtons.Right;
2200 break;
2203 args = new MouseEventArgs (mb, mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()), 0);
2204 active_tracker.OnMouseUp(new MouseEventArgs (args.Button, args.Clicks, Control.MousePosition.X, Control.MousePosition.Y, args.Delta));
2205 mouse_clicks = 1;
2206 return;
2208 base.WndProc(ref m);
2209 return;
2212 case Msg.WM_GETMINMAXINFO: {
2213 MINMAXINFO mmi;
2215 if (m.LParam != IntPtr.Zero) {
2216 mmi = (MINMAXINFO)Marshal.PtrToStructure(m.LParam, typeof(MINMAXINFO));
2218 default_maximized_bounds = new Rectangle(mmi.ptMaxPosition.x, mmi.ptMaxPosition.y, mmi.ptMaxSize.x, mmi.ptMaxSize.y);
2219 if (maximized_bounds != Rectangle.Empty) {
2220 mmi.ptMaxPosition.x = maximized_bounds.Left;
2221 mmi.ptMaxPosition.y = maximized_bounds.Top;
2222 mmi.ptMaxSize.x = maximized_bounds.Width;
2223 mmi.ptMaxSize.y = maximized_bounds.Height;
2226 if (minimum_size != Size.Empty) {
2227 mmi.ptMinTrackSize.x = minimum_size.Width;
2228 mmi.ptMinTrackSize.y = minimum_size.Height;
2231 if (maximum_size != Size.Empty) {
2232 mmi.ptMaxTrackSize.x = maximum_size.Width;
2233 mmi.ptMaxTrackSize.y = maximum_size.Height;
2235 Marshal.StructureToPtr(mmi, m.LParam, false);
2237 break;
2240 #if NET_2_0
2241 case Msg.WM_MOUSEACTIVATE: {
2242 // Let *Strips know the form or another control has been clicked
2243 if (XplatUI.IsEnabled (Handle))
2244 ToolStripManager.FireAppClicked ();
2246 base.WndProc (ref m);
2247 break;
2250 case Msg.WM_ACTIVATEAPP: {
2251 // Let *Strips know the app lost focus
2252 if (m.WParam == (IntPtr)0)
2253 if (XplatUI.IsEnabled (Handle))
2254 ToolStripManager.FireAppFocusChanged (this);
2256 base.WndProc (ref m);
2257 break;
2259 #endif
2261 default: {
2262 base.WndProc (ref m);
2263 break;
2267 #endregion // Protected Instance Methods
2269 internal override void FireEnter ()
2271 // do nothing - forms don't generate OnEnter
2274 internal override void FireLeave ()
2276 // do nothing - forms don't generate OnLeave
2279 internal void RemoveWindowManager ()
2281 window_manager = null;
2284 internal override void CheckAcceptButton()
2286 if (accept_button != null) {
2287 Button a_button = accept_button as Button;
2289 if (ActiveControl == a_button)
2290 return;
2292 if (ActiveControl is Button) {
2293 a_button.paint_as_acceptbutton = false;
2294 a_button.Redraw();
2295 return;
2296 } else {
2297 a_button.paint_as_acceptbutton = true;
2298 a_button.Redraw();
2303 #region Events
2304 static object ActivatedEvent = new object ();
2305 static object ClosedEvent = new object ();
2306 static object ClosingEvent = new object ();
2307 static object DeactivateEvent = new object ();
2308 static object InputLanguageChangedEvent = new object ();
2309 static object InputLanguageChangingEvent = new object ();
2310 static object LoadEvent = new object ();
2311 static object MaximizedBoundsChangedEvent = new object ();
2312 static object MaximumSizeChangedEvent = new object ();
2313 static object MdiChildActivateEvent = new object ();
2314 static object MenuCompleteEvent = new object ();
2315 static object MenuStartEvent = new object ();
2316 static object MinimumSizeChangedEvent = new object ();
2318 public event EventHandler Activated {
2319 add { Events.AddHandler (ActivatedEvent, value); }
2320 remove { Events.RemoveHandler (ActivatedEvent, value); }
2323 #if NET_2_0
2324 [Browsable (false)]
2325 [EditorBrowsable (EditorBrowsableState.Never)]
2326 #endif
2327 public event EventHandler Closed {
2328 add { Events.AddHandler (ClosedEvent, value); }
2329 remove { Events.RemoveHandler (ClosedEvent, value); }
2332 #if NET_2_0
2333 [Browsable (false)]
2334 [EditorBrowsable (EditorBrowsableState.Never)]
2335 #endif
2336 public event CancelEventHandler Closing {
2337 add { Events.AddHandler (ClosingEvent, value); }
2338 remove { Events.RemoveHandler (ClosingEvent, value); }
2341 public event EventHandler Deactivate {
2342 add { Events.AddHandler (DeactivateEvent, value); }
2343 remove { Events.RemoveHandler (DeactivateEvent, value); }
2346 public event InputLanguageChangedEventHandler InputLanguageChanged {
2347 add { Events.AddHandler (InputLanguageChangedEvent, value); }
2348 remove { Events.RemoveHandler (InputLanguageChangedEvent, value); }
2351 public event InputLanguageChangingEventHandler InputLanguageChanging {
2352 add { Events.AddHandler (InputLanguageChangingEvent, value); }
2353 remove { Events.RemoveHandler (InputLanguageChangingEvent, value); }
2356 public event EventHandler Load {
2357 add { Events.AddHandler (LoadEvent, value); }
2358 remove { Events.RemoveHandler (LoadEvent, value); }
2361 public event EventHandler MaximizedBoundsChanged {
2362 add { Events.AddHandler (MaximizedBoundsChangedEvent, value); }
2363 remove { Events.RemoveHandler (MaximizedBoundsChangedEvent, value); }
2366 public event EventHandler MaximumSizeChanged {
2367 add { Events.AddHandler (MaximumSizeChangedEvent, value); }
2368 remove { Events.RemoveHandler (MaximumSizeChangedEvent, value); }
2371 public event EventHandler MdiChildActivate {
2372 add { Events.AddHandler (MdiChildActivateEvent, value); }
2373 remove { Events.RemoveHandler (MdiChildActivateEvent, value); }
2376 #if NET_2_0
2377 [Browsable (false)]
2378 #endif
2379 public event EventHandler MenuComplete {
2380 add { Events.AddHandler (MenuCompleteEvent, value); }
2381 remove { Events.RemoveHandler (MenuCompleteEvent, value); }
2384 #if NET_2_0
2385 [Browsable (false)]
2386 #endif
2387 public event EventHandler MenuStart {
2388 add { Events.AddHandler (MenuStartEvent, value); }
2389 remove { Events.RemoveHandler (MenuStartEvent, value); }
2392 public event EventHandler MinimumSizeChanged {
2393 add { Events.AddHandler (MinimumSizeChangedEvent, value); }
2394 remove { Events.RemoveHandler (MinimumSizeChangedEvent, value); }
2398 [Browsable(false)]
2399 [EditorBrowsable(EditorBrowsableState.Never)]
2400 public new event EventHandler TabIndexChanged {
2401 add { base.TabIndexChanged += value; }
2402 remove { base.TabIndexChanged -= value; }
2404 #endregion // Events
2406 #if NET_2_0
2407 [SettingsBindable (true)]
2408 public override string Text {
2409 get {
2410 return base.Text;
2413 set {
2414 base.Text = value;
2418 [SettingsBindable (true)]
2419 public new Point Location {
2420 get {
2421 return base.Location;
2424 set {
2425 base.Location = value;
2429 static object AutoValidateChangedEvent = new object ();
2430 static object FormClosingEvent = new object ();
2431 static object FormClosedEvent = new object ();
2432 static object HelpButtonClickedEvent = new object ();
2433 static object ResizeEndEvent = new object ();
2434 static object ResizeBeginEvent = new object ();
2435 static object RightToLeftLayoutChangedEvent = new object ();
2436 static object ShownEvent = new object ();
2438 [Browsable (true)]
2439 [EditorBrowsable (EditorBrowsableState.Always)]
2440 public new event EventHandler AutoSizeChanged {
2441 add { base.AutoSizeChanged += value; }
2442 remove { base.AutoSizeChanged -= value; }
2445 [Browsable (true)]
2446 [EditorBrowsable (EditorBrowsableState.Always)]
2447 public event EventHandler AutoValidateChanged {
2448 add { Events.AddHandler (AutoValidateChangedEvent, value); }
2449 remove { Events.RemoveHandler (AutoValidateChangedEvent, value); }
2452 public event FormClosingEventHandler FormClosing {
2453 add { Events.AddHandler (FormClosingEvent, value); }
2454 remove { Events.RemoveHandler (FormClosingEvent, value); }
2457 public event FormClosedEventHandler FormClosed {
2458 add { Events.AddHandler (FormClosedEvent, value); }
2459 remove { Events.RemoveHandler (FormClosedEvent, value); }
2462 [Browsable (true)]
2463 [EditorBrowsable (EditorBrowsableState.Always)]
2464 public event CancelEventHandler HelpButtonClicked {
2465 add { Events.AddHandler (HelpButtonClickedEvent, value); }
2466 remove { Events.RemoveHandler (HelpButtonClickedEvent, value); }
2469 [Browsable (false)]
2470 [EditorBrowsable (EditorBrowsableState.Never)]
2471 public new event EventHandler MarginChanged {
2472 add { base.MarginChanged += value; }
2473 remove { base.MarginChanged -= value; }
2476 public event EventHandler RightToLeftLayoutChanged {
2477 add { Events.AddHandler (RightToLeftLayoutChangedEvent, value); }
2478 remove { Events.RemoveHandler (RightToLeftLayoutChangedEvent, value); }
2481 public event EventHandler ResizeBegin {
2482 add { Events.AddHandler (ResizeBeginEvent, value); }
2483 remove { Events.RemoveHandler (ResizeBeginEvent, value); }
2486 public event EventHandler ResizeEnd {
2487 add { Events.AddHandler (ResizeEndEvent, value); }
2488 remove { Events.RemoveHandler (ResizeEndEvent, value); }
2491 public event EventHandler Shown {
2492 add { Events.AddHandler (ShownEvent, value); }
2493 remove { Events.RemoveHandler (ShownEvent, value); }
2496 [Browsable (false)]
2497 [EditorBrowsable (EditorBrowsableState.Never)]
2498 public new event EventHandler TabStopChanged {
2499 add { base.TabStopChanged += value; }
2500 remove { base.TabStopChanged -= value; }
2504 [EditorBrowsable (EditorBrowsableState.Always)]
2505 protected override void OnBackgroundImageChanged (EventArgs e)
2507 base.OnBackgroundImageChanged (e);
2510 [EditorBrowsable (EditorBrowsableState.Always)]
2511 protected override void OnBackgroundImageLayoutChanged (EventArgs e)
2513 base.OnBackgroundImageLayoutChanged (e);
2516 [EditorBrowsable (EditorBrowsableState.Advanced)]
2517 protected override void OnEnabledChanged (EventArgs e)
2519 base.OnEnabledChanged (e);
2522 [EditorBrowsable (EditorBrowsableState.Advanced)]
2523 protected override void OnEnter (EventArgs e)
2525 base.OnEnter (e);
2528 [EditorBrowsable (EditorBrowsableState.Advanced)]
2529 protected virtual void OnFormClosed (FormClosedEventArgs e) {
2530 FormClosedEventHandler eh = (FormClosedEventHandler)(Events[FormClosedEvent]);
2531 if (eh != null)
2532 eh (this, e);
2535 // Consider calling FireClosingEvents instead of calling this directly.
2536 [EditorBrowsable (EditorBrowsableState.Advanced)]
2537 protected virtual void OnFormClosing (FormClosingEventArgs e)
2539 FormClosingEventHandler eh = (FormClosingEventHandler)(Events [FormClosingEvent]);
2540 if (eh != null)
2541 eh (this, e);
2544 [MonoTODO ("Not hooked up to event")]
2545 [EditorBrowsable (EditorBrowsableState.Advanced)]
2546 protected virtual void OnHelpButtonClicked (CancelEventArgs e)
2548 CancelEventHandler eh = (CancelEventHandler)(Events[HelpButtonClickedEvent]);
2549 if (eh != null)
2550 eh (this, e);
2553 [EditorBrowsable (EditorBrowsableState.Advanced)]
2554 protected override void OnLayout (LayoutEventArgs levent)
2556 base.OnLayout (levent);
2559 [EditorBrowsable (EditorBrowsableState.Advanced)]
2560 protected virtual void OnResizeBegin (EventArgs e)
2562 EventHandler eh = (EventHandler) (Events [ResizeBeginEvent]);
2563 if (eh != null)
2564 eh (this, e);
2567 [EditorBrowsable (EditorBrowsableState.Advanced)]
2568 protected virtual void OnResizeEnd (EventArgs e)
2570 EventHandler eh = (EventHandler) (Events [ResizeEndEvent]);
2571 if (eh != null)
2572 eh (this, e);
2575 [EditorBrowsable (EditorBrowsableState.Advanced)]
2576 protected virtual void OnShown (EventArgs e)
2578 EventHandler eh = (EventHandler) (Events [ShownEvent]);
2579 if (eh != null)
2580 eh (this, e);
2582 #endif