GroupBox.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. //
  2. // System.Windows.Forms.GroupBox.cs
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining
  5. // a copy of this software and associated documentation files (the
  6. // "Software"), to deal in the Software without restriction, including
  7. // without limitation the rights to use, copy, modify, merge, publish,
  8. // distribute, sublicense, and/or sell copies of the Software, and to
  9. // permit persons to whom the Software is furnished to do so, subject to
  10. // the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be
  13. // included in all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  19. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  20. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  21. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. //
  23. // Authors:
  24. // Jordi Mas i Hernandez, [email protected]
  25. //
  26. // TODO:
  27. //
  28. // Copyright (C) Novell Inc., 2004-2005
  29. //
  30. //
  31. // COMPLETE
  32. using System.Drawing;
  33. using System.ComponentModel;
  34. using System.ComponentModel.Design;
  35. namespace System.Windows.Forms
  36. {
  37. [DefaultProperty("Text")]
  38. [DefaultEvent("Enter")]
  39. [Designer ("System.Windows.Forms.Design.GroupBoxDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
  40. public class GroupBox : Control
  41. {
  42. private FlatStyle flat_style;
  43. private Rectangle display_rectangle = new Rectangle ();
  44. #region Events
  45. [Browsable(false)]
  46. [EditorBrowsable(EditorBrowsableState.Advanced)]
  47. public new event EventHandler Click;
  48. [Browsable(false)]
  49. [EditorBrowsable(EditorBrowsableState.Advanced)]
  50. public new event EventHandler DoubleClick;
  51. [Browsable(false)]
  52. [EditorBrowsable(EditorBrowsableState.Advanced)]
  53. public new event KeyEventHandler KeyDown;
  54. [Browsable(false)]
  55. [EditorBrowsable(EditorBrowsableState.Advanced)]
  56. public new event KeyPressEventHandler KeyPress;
  57. [Browsable(false)]
  58. [EditorBrowsable(EditorBrowsableState.Advanced)]
  59. public new event KeyEventHandler KeyUp;
  60. [Browsable(false)]
  61. [EditorBrowsable(EditorBrowsableState.Advanced)]
  62. public new event MouseEventHandler MouseDown;
  63. [Browsable(false)]
  64. [EditorBrowsable(EditorBrowsableState.Advanced)]
  65. public new event EventHandler MouseEnter;
  66. [Browsable(false)]
  67. [EditorBrowsable(EditorBrowsableState.Advanced)]
  68. public new event EventHandler MouseLeave;
  69. [Browsable(false)]
  70. [EditorBrowsable(EditorBrowsableState.Advanced)]
  71. public new event MouseEventHandler MouseMove;
  72. [Browsable(false)]
  73. [EditorBrowsable(EditorBrowsableState.Advanced)]
  74. public new event MouseEventHandler MouseUp;
  75. [Browsable(false)]
  76. [EditorBrowsable(EditorBrowsableState.Advanced)]
  77. public new event EventHandler TabStopChanged;
  78. #endregion Events
  79. public GroupBox ()
  80. {
  81. TabStop = false;
  82. flat_style = FlatStyle.Standard;
  83. SetStyle(ControlStyles.ContainerControl | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor, true);
  84. SetStyle(ControlStyles.Selectable, false);
  85. }
  86. #region Public Properties
  87. [Browsable(false)]
  88. [EditorBrowsable(EditorBrowsableState.Advanced)]
  89. public override bool AllowDrop {
  90. get { return base.AllowDrop; }
  91. set { base.AllowDrop = value; }
  92. }
  93. protected override CreateParams CreateParams {
  94. get { return base.CreateParams; }
  95. }
  96. protected override Size DefaultSize {
  97. get { return ThemeEngine.Current.GroupBoxDefaultSize;}
  98. }
  99. public override Rectangle DisplayRectangle {
  100. get {
  101. display_rectangle.X = 3;
  102. display_rectangle.Y = Font.Height + 3;
  103. display_rectangle.Width = Width - 6;
  104. display_rectangle.Height = Height - Font.Height - 6;
  105. return display_rectangle;
  106. }
  107. }
  108. [DefaultValue(FlatStyle.Standard)]
  109. public FlatStyle FlatStyle {
  110. get { return flat_style; }
  111. set {
  112. if (!Enum.IsDefined (typeof (FlatStyle), value))
  113. new InvalidEnumArgumentException (string.Format("Enum argument value '{0}' is not valid for FlatStyle", value));
  114. if (flat_style == value)
  115. return;
  116. flat_style = value;
  117. Refresh ();
  118. }
  119. }
  120. [Browsable(false)]
  121. [EditorBrowsable(EditorBrowsableState.Advanced)]
  122. public new bool TabStop {
  123. get { return base.TabStop; }
  124. set { base.TabStop = value; }
  125. }
  126. [Localizable(true)]
  127. public override string Text {
  128. get { return base.Text; }
  129. set {
  130. if (base.Text == value)
  131. return;
  132. base.Text = value;
  133. Refresh ();
  134. }
  135. }
  136. #endregion //Public Properties
  137. #region Public Methods
  138. protected override void OnFontChanged (EventArgs e)
  139. {
  140. base.OnFontChanged (e);
  141. Refresh ();
  142. }
  143. protected override void OnPaint (PaintEventArgs pevent)
  144. {
  145. ThemeEngine.Current.DrawGroupBox (pevent.Graphics, ClientRectangle, this);
  146. base.OnPaint(pevent);
  147. }
  148. protected override bool ProcessMnemonic (char charCode)
  149. {
  150. if (IsMnemonic(charCode, Text) == true) {
  151. // Select item next in line in tab order
  152. if (this.parent != null) {
  153. parent.SelectNextControl(this, true, false, true, false);
  154. }
  155. return true;
  156. }
  157. return base.ProcessMnemonic (charCode);
  158. }
  159. public override string ToString()
  160. {
  161. return GetType ().FullName.ToString () + ", Text: " + Text;
  162. }
  163. protected override void WndProc(ref Message m) {
  164. switch ((Msg) m.Msg) {
  165. case Msg.WM_ERASEBKGND:
  166. m.Result = (IntPtr)1;
  167. break;
  168. default:
  169. base.WndProc (ref m);
  170. break;
  171. }
  172. }
  173. #endregion Public Methods
  174. }
  175. }