Card.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Drawing.Drawing2D;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. namespace ImpulseVision
  12. {
  13. public class FDCard : Control
  14. {
  15. #region -- Переменные --
  16. Animation animCurtain;
  17. private float CurtainHeight;
  18. private int CurtainMinHeight = 50;
  19. private bool MouseEntered = false;
  20. private bool MousePressed = false;
  21. StringFormat SF = new StringFormat();
  22. #endregion
  23. #region -- Свойства --
  24. public string TextHeader { get; set; } = "Header";
  25. public Font FontHeader { get; set; } = new Font("Verdana", 12F, FontStyle.Bold);
  26. public Color ForeColorHeader { get; set; } = Color.White;
  27. public string TextDescrition { get; set; } = "Your description text for this control";
  28. public Font FontDescrition { get; set; } = new Font("Verdana", 8.25F, FontStyle.Regular);
  29. public Color ForeColorDescrition { get; set; } = Color.Black;
  30. public Color BackColorCurtain { get; set; } = FlatColors.Red;
  31. #endregion
  32. public FDCard()
  33. {
  34. SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor | ControlStyles.UserPaint, true);
  35. DoubleBuffered = true;
  36. Size = new Size(250, 200);
  37. CurtainHeight = Height - 60;
  38. Font = new Font("Verdana", 9F, FontStyle.Regular);
  39. BackColor = Color.White;
  40. animCurtain = new Animation();
  41. animCurtain.Value = CurtainHeight;
  42. SF.Alignment = StringAlignment.Near;
  43. SF.LineAlignment = StringAlignment.Near;
  44. Cursor = Cursors.Hand;
  45. }
  46. protected override void OnPaint(PaintEventArgs e)
  47. {
  48. base.OnPaint(e);
  49. Graphics graph = e.Graphics;
  50. graph.SmoothingMode = SmoothingMode.HighQuality;
  51. graph.Clear(Parent.BackColor);
  52. Rectangle rect = new Rectangle(0, 0, Width - 1, Height - 1);
  53. Rectangle rectCurtain = new Rectangle(0, 0, Width - 1, (int)animCurtain.Value);
  54. Rectangle rectDescription = new Rectangle(15, CurtainMinHeight + 5, rect.Width - 30, rect.Height - 100);
  55. //Фон
  56. graph.FillRectangle(new SolidBrush(BackColor), rect);
  57. //Шторка
  58. graph.DrawRectangle(new Pen(BackColorCurtain), rectCurtain);
  59. graph.FillRectangle(new SolidBrush(BackColorCurtain), rectCurtain);
  60. //Обводка
  61. //graph.DrawRectangle(new Pen(FlatColors.Gray), rect);
  62. if (animCurtain.Value == CurtainMinHeight)
  63. {
  64. graph.DrawString(TextDescrition, FontDescrition, new SolidBrush(ForeColorDescrition), rectDescription, SF);
  65. //debug: //graph.DrawRectangle(new Pen(Color.Blue), rectDescription);
  66. }
  67. graph.DrawString(Text, Font, new SolidBrush(ForeColor), 15, Height - 37);
  68. graph.DrawString(TextHeader, FontHeader, new SolidBrush(ForeColorHeader),
  69. new Rectangle(15, 15, rectCurtain.Width, rectCurtain.Height));
  70. }
  71. protected override void OnSizeChanged(EventArgs e)
  72. {
  73. base.OnSizeChanged(e);
  74. if (Height <= 100)
  75. Height = 100;
  76. if (Width <= 100)
  77. Width = 100;
  78. CurtainHeight = Height - 60;
  79. animCurtain = new Animation();
  80. animCurtain.Value = CurtainHeight;
  81. Invalidate();
  82. }
  83. protected override void OnMouseEnter(EventArgs e)
  84. {
  85. base.OnMouseEnter(e);
  86. MouseEntered = true;
  87. DoCurtainAnimation();
  88. //Invalidate();
  89. }
  90. protected override void OnMouseLeave(EventArgs e)
  91. {
  92. base.OnMouseLeave(e);
  93. MouseEntered = false;
  94. DoCurtainAnimation();
  95. //Invalidate();
  96. }
  97. protected override void OnMouseDown(MouseEventArgs e)
  98. {
  99. base.OnMouseDown(e);
  100. MousePressed = true;
  101. Invalidate();
  102. }
  103. protected override void OnMouseUp(MouseEventArgs e)
  104. {
  105. base.OnMouseUp(e);
  106. MousePressed = false;
  107. Invalidate();
  108. }
  109. private void DoCurtainAnimation()
  110. {
  111. if (MouseEntered == true)
  112. {
  113. animCurtain = new Animation("Curtain_" + Handle, Invalidate, animCurtain.Value, CurtainMinHeight);
  114. }
  115. else
  116. {
  117. animCurtain = new Animation("Curtain_" + Handle, Invalidate, animCurtain.Value, CurtainHeight);
  118. }
  119. Animator.Request(animCurtain, true);
  120. }
  121. }
  122. }