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