BorderSample.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. using FastReport.Utils;
  2. using System.ComponentModel;
  3. using System.Drawing;
  4. using System.Windows.Forms;
  5. namespace FastReport.Controls
  6. {
  7. internal class ToggleLineEventArgs
  8. {
  9. private Border border;
  10. private BorderLines line;
  11. private bool toggle;
  12. public Border Border
  13. {
  14. get { return border; }
  15. set { border = value; }
  16. }
  17. public BorderLines Line
  18. {
  19. get { return line; }
  20. set { line = value; }
  21. }
  22. public bool Toggle
  23. {
  24. get { return toggle; }
  25. set { toggle = value; }
  26. }
  27. public ToggleLineEventArgs(Border border, BorderLines line, bool toggle)
  28. {
  29. Border = border;
  30. Line = line;
  31. Toggle = toggle;
  32. }
  33. }
  34. internal delegate void ToggleLineEventHandler(object sender, ToggleLineEventArgs e);
  35. internal class BorderSample : Control
  36. {
  37. private Border border;
  38. public event ToggleLineEventHandler ToggleLine;
  39. [Browsable(false)]
  40. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  41. public Border Border
  42. {
  43. get { return border; }
  44. set { border = value; }
  45. }
  46. protected override void OnPaint(PaintEventArgs e)
  47. {
  48. Graphics g = e.Graphics;
  49. int _5 = this.LogicalToDevice(5);
  50. int _6 = this.LogicalToDevice(6);
  51. int _10 = this.LogicalToDevice(10);
  52. int _11 = this.LogicalToDevice(11);
  53. // draw control frame
  54. this.DrawVisualStyleBorder(g, new Rectangle(0, 0, Width - 1, Height - 1));
  55. // draw corners
  56. Pen p = SystemPens.ControlDark;
  57. g.DrawLine(p, _10, _10, _10, _5);
  58. g.DrawLine(p, _10, _10, _5, _10);
  59. g.DrawLine(p, _10, Height - _11, _10, Height - _6);
  60. g.DrawLine(p, _10, Height - _11, _5, Height - _11);
  61. g.DrawLine(p, Width - _11, _10, Width - _11, _5);
  62. g.DrawLine(p, Width - _11, _10, Width - _6, _10);
  63. g.DrawLine(p, Width - _11, Height - _11, Width - _11, Height - _6);
  64. g.DrawLine(p, Width - _11, Height - _11, Width - _6, Height - _11);
  65. // draw text
  66. using (var sf = new StringFormat())
  67. {
  68. sf.Alignment = StringAlignment.Center;
  69. sf.LineAlignment = StringAlignment.Center;
  70. g.DrawString(Res.Get("Misc,Sample"), Font, SystemBrushes.WindowText, DisplayRectangle, sf);
  71. }
  72. // draw border
  73. if (Border != null)
  74. {
  75. using (var cache = new GraphicCache())
  76. {
  77. float scale = this.DpiMultiplier();
  78. Border.Draw(new FRPaintEventArgs(g, scale, scale, cache), new RectangleF(10, 10, Width / scale - 21, Height / scale - 21));
  79. }
  80. }
  81. }
  82. protected override void OnMouseDown(MouseEventArgs e)
  83. {
  84. int _5 = this.LogicalToDevice(5);
  85. int _12 = this.LogicalToDevice(12);
  86. int _18 = this.LogicalToDevice(18);
  87. BorderLines line = BorderLines.None;
  88. if (e.X > _12 && e.X < Width - _12 && e.Y > _5 && e.Y < _18)
  89. line = BorderLines.Top;
  90. else if (e.X > _12 && e.X < Width - _12 && e.Y > Height - _18 && e.Y < Height - _5)
  91. line = BorderLines.Bottom;
  92. else if (e.X > _5 && e.X < _18 && e.Y > _12 && e.Y < Height - _12)
  93. line = BorderLines.Left;
  94. else if (e.X > Width - _18 && e.X < Width - _5 && e.Y > _12 && e.Y < Height - _12)
  95. line = BorderLines.Right;
  96. if (Border != null && ToggleLine != null)
  97. {
  98. ToggleLine(this, new ToggleLineEventArgs(Border, line, (Border.Lines & line) == 0));
  99. Refresh();
  100. }
  101. }
  102. public void UpdateDpiDependencies(Control owner)
  103. {
  104. #if MONO
  105. // WPF: fix issues with multi-monitor dpi. Dropdown will be scaled automatically
  106. owner = this;
  107. #endif
  108. if (owner == null)
  109. return;
  110. Size = owner.LogicalToDevice(new Size(160, 94));
  111. }
  112. public BorderSample()
  113. {
  114. SetStyle(ControlStyles.AllPaintingInWmPaint, true);
  115. SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
  116. BackColor = SystemColors.Window;
  117. Size = new Size(160, 94);
  118. }
  119. }
  120. }