CTextBox.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. using System;
  2. using System.Windows.Forms;
  3. using System.Drawing;
  4. using System.ComponentModel;
  5. using CustomControls.Enumerations;
  6. namespace CustomControls.Win32Controls
  7. {
  8. public class CTextBox:TextBox
  9. {
  10. #region "Variables"
  11. CustomControls.Enumerations.State _State=CustomControls.Enumerations.State.Normal;
  12. #endregion
  13. #region "Properties"
  14. protected State State
  15. {
  16. get{return _State;}
  17. set
  18. {
  19. if(value!=_State)
  20. {
  21. _State= value;
  22. Invalidate();
  23. }
  24. }
  25. }
  26. [Browsable(false)]
  27. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  28. public new BorderStyle BorderStyle
  29. {
  30. get{return BorderStyle.FixedSingle;}
  31. }
  32. #endregion
  33. #region "Constructor"
  34. public CTextBox()
  35. {
  36. base.BorderStyle=BorderStyle.FixedSingle;
  37. //keep it like that!
  38. }
  39. #endregion
  40. #region "Override"
  41. protected override void OnMouseEnter(EventArgs e)
  42. {
  43. base.OnMouseEnter(e);
  44. State = State.Hot;
  45. }
  46. protected override void OnMouseLeave(EventArgs e)
  47. {
  48. base.OnMouseLeave(e);
  49. if ( !ContainsFocus )
  50. {
  51. State = State.Normal;
  52. }
  53. }
  54. protected override void OnGotFocus(EventArgs e)
  55. {
  56. base.OnGotFocus(e);
  57. State = State.Hot;
  58. }
  59. protected override void OnLostFocus(EventArgs e)
  60. {
  61. base.OnLostFocus(e);
  62. State=State.Normal;
  63. }
  64. protected override void WndProc(ref Message m)
  65. {
  66. base.WndProc(ref m);
  67. if(m.Msg==(int)Msgs.WM_PAINT)
  68. {
  69. PaintBorder(this.State);
  70. }
  71. }
  72. #endregion
  73. #region"Implementation"
  74. private void PaintBorder(State state)
  75. {
  76. using (Graphics g=this.CreateGraphics())
  77. {
  78. Color borderColor;
  79. if(Enabled)
  80. {
  81. if (State==State.Normal)
  82. {
  83. if(ReadOnly){borderColor=CustomControls.BaseClasses.AppColors.ToolbarColorLight;}
  84. else {borderColor=(this.Parent!=null)?Parent.BackColor:CustomControls.BaseClasses.AppColors.ControlColor;}
  85. }
  86. else{borderColor= CustomControls.BaseClasses.AppColors.HighlightColorDarkDark;}
  87. }
  88. else{borderColor=CustomControls.BaseClasses.AppColors.ToolbarBackColor;}
  89. using (Pen pen= new Pen(borderColor))
  90. {
  91. g.DrawRectangle(pen,new Rectangle(0,0,this.Width-1, this.Height-1));
  92. }
  93. }
  94. }
  95. #endregion
  96. }
  97. }