GroupBox.cs 4.2 KB

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