BorderSample.cs 3.9 KB

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