GroupBox.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. // Autors:
  24. // Jordi Mas i Hernandez, [email protected]
  25. //
  26. // TODO:
  27. //
  28. // Copyright (C) Novell Inc., 2004
  29. //
  30. //
  31. // COMPLETE
  32. using System.Drawing;
  33. using System.ComponentModel;
  34. namespace System.Windows.Forms
  35. {
  36. public class GroupBox : Control
  37. {
  38. private FlatStyle flat_style;
  39. private Rectangle display_rectangle = new Rectangle ();
  40. #region Events
  41. public new event EventHandler Click;
  42. public new event EventHandler DoubleClick;
  43. public new event KeyEventHandler KeyDown;
  44. public new event KeyPressEventHandler KeyPress;
  45. public new event KeyEventHandler KeyUp;
  46. public new event MouseEventHandler MouseDown;
  47. public new event EventHandler MouseEnter;
  48. public new event EventHandler MouseLeave;
  49. public new event MouseEventHandler MouseMove;
  50. public new event MouseEventHandler MouseUp;
  51. public new event EventHandler TabStopChanged;
  52. #endregion Events
  53. public GroupBox ()
  54. {
  55. TabStop = false;
  56. flat_style = FlatStyle.Standard;
  57. SetStyle(ControlStyles.ContainerControl, true);
  58. }
  59. #region Public Properties
  60. public override bool AllowDrop {
  61. get { return base.AllowDrop; }
  62. set { base.AllowDrop = value; }
  63. }
  64. protected override CreateParams CreateParams {
  65. get { return base.CreateParams; }
  66. }
  67. protected override Size DefaultSize {
  68. get { return ThemeEngine.Current.GroupBoxDefaultSize;}
  69. }
  70. public override Rectangle DisplayRectangle {
  71. get {
  72. display_rectangle.X = 3;
  73. display_rectangle.Y = Font.Height + 3;
  74. display_rectangle.Width = Width - 6;
  75. display_rectangle.Height = Height - Font.Height - 6;
  76. return display_rectangle;
  77. }
  78. }
  79. public FlatStyle FlatStyle {
  80. get { return flat_style; }
  81. set {
  82. if (!Enum.IsDefined (typeof (FlatStyle), value))
  83. new InvalidEnumArgumentException (string.Format("Enum argument value '{0}' is not valid for FlatStyle", value));
  84. if (flat_style == value)
  85. return;
  86. flat_style = value;
  87. Refresh ();
  88. }
  89. }
  90. public new bool TabStop {
  91. get { return base.TabStop; }
  92. set { base.TabStop = value; }
  93. }
  94. public override string Text {
  95. get { return base.Text; }
  96. set {
  97. if (base.Text == value)
  98. return;
  99. base.Text = value;
  100. Refresh ();
  101. }
  102. }
  103. #endregion //Public Properties
  104. #region Public Methods
  105. protected override void OnFontChanged (EventArgs e)
  106. {
  107. base.OnFontChanged (e);
  108. Refresh ();
  109. }
  110. protected override void OnPaint (PaintEventArgs pevent)
  111. {
  112. Draw ();
  113. pevent.Graphics.DrawImage (ImageBuffer, 0, 0);
  114. }
  115. protected override bool ProcessMnemonic (char charCode)
  116. {
  117. return base.ProcessMnemonic(charCode);
  118. }
  119. public override string ToString()
  120. {
  121. return GetType ().FullName.ToString () + ", Text: " + Text;
  122. }
  123. protected override void WndProc(ref Message m) {
  124. switch ((Msg) m.Msg) {
  125. case Msg.WM_ERASEBKGND:
  126. m.Result = (IntPtr)1;
  127. break;
  128. default:
  129. base.WndProc (ref m);
  130. break;
  131. }
  132. }
  133. #endregion Public Methods
  134. #region Private Methods
  135. private void Draw ()
  136. {
  137. ThemeEngine.Current.DrawGroupBox (DeviceContext, ClientRectangle, this);
  138. }
  139. #endregion // Private Methods
  140. }
  141. }