Grid.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Drawing;
  5. namespace FastReport.Design.PageDesigners.Dialog
  6. {
  7. internal class Grid : GridBase
  8. {
  9. private float snapSize;
  10. private Bitmap gridBmp;
  11. public override float SnapSize
  12. {
  13. get { return snapSize; }
  14. set
  15. {
  16. snapSize = value;
  17. ResetGridBmp();
  18. }
  19. }
  20. private void ResetGridBmp()
  21. {
  22. gridBmp = new Bitmap(1, 1);
  23. }
  24. public void Draw(Graphics g, Rectangle visibleArea)
  25. {
  26. if (visibleArea.Width > 0 && visibleArea.Height > 0 && SnapSize > 2)
  27. {
  28. int i = 0;
  29. if (gridBmp.Width != visibleArea.Width)
  30. {
  31. gridBmp = new Bitmap(visibleArea.Width, 1);
  32. // draw points on one line
  33. i = 0;
  34. while (i < visibleArea.Width)
  35. {
  36. gridBmp.SetPixel(i, 0, Color.Gray);
  37. i += (int)SnapSize;
  38. }
  39. }
  40. // draw lines
  41. i = visibleArea.Top;
  42. while (i < visibleArea.Bottom)
  43. {
  44. g.DrawImage(gridBmp, visibleArea.Left, i);
  45. i += (int)SnapSize;
  46. }
  47. }
  48. }
  49. public Grid()
  50. {
  51. SnapSize = 8;
  52. }
  53. }
  54. }