[2768] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Text;
|
---|
| 4 | using System.Drawing;
|
---|
| 5 | using System.Windows.Forms;
|
---|
| 6 | using System.Drawing.Drawing2D;
|
---|
| 7 |
|
---|
| 8 | namespace Netron.Diagramming.Core
|
---|
| 9 | {
|
---|
| 10 | public class Grid
|
---|
| 11 | {
|
---|
| 12 | // ------------------------------------------------------------------
|
---|
| 13 | /// <summary>
|
---|
| 14 | /// Constructor.
|
---|
| 15 | /// </summary>
|
---|
| 16 | // ------------------------------------------------------------------
|
---|
| 17 | public Grid()
|
---|
| 18 | {
|
---|
| 19 | }
|
---|
| 20 |
|
---|
| 21 | public static void Paint(
|
---|
| 22 | Graphics g,
|
---|
| 23 | RectangleF area,
|
---|
| 24 | float horizontalSpacing,
|
---|
| 25 | float verticalSpacing,
|
---|
| 26 | float penWidth)
|
---|
| 27 | {
|
---|
| 28 | //ControlPaint.DrawGrid(
|
---|
| 29 | // g,
|
---|
| 30 | // area,
|
---|
| 31 | // new Size(20, 20),
|
---|
| 32 | // Color.Wheat);
|
---|
| 33 |
|
---|
| 34 | //g.SmoothingMode = SmoothingMode.HighQuality;
|
---|
| 35 | //g.CompositingQuality = CompositingQuality.HighQuality;
|
---|
| 36 | //g.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
---|
| 37 | g.SetClip(area);
|
---|
| 38 | float sideLength = Math.Min(area.Width, area.Height);
|
---|
| 39 | float horizSpacing = sideLength / horizontalSpacing;
|
---|
| 40 | float vertSpacing = sideLength / verticalSpacing;
|
---|
| 41 |
|
---|
| 42 | Pen majorPen = new Pen(Color.DarkGray);
|
---|
| 43 | majorPen.Width = penWidth;
|
---|
| 44 | majorPen.DashStyle = DashStyle.Dot;
|
---|
| 45 |
|
---|
| 46 | float top = area.Top; // The top y coord.
|
---|
| 47 | float bottom = area.Bottom; // The bottom y coord.
|
---|
| 48 | float left = area.Left; // The left y coord.
|
---|
| 49 | float right = area.Right; // The right y coord.
|
---|
| 50 | PointF p1; // The starting point for the grid line.
|
---|
| 51 | PointF p2; // The end point for the grid line.
|
---|
| 52 |
|
---|
| 53 | // Draw the horizontal lines, starting at the top.
|
---|
| 54 | for (float i = top; i <= bottom; i += horizontalSpacing)
|
---|
| 55 | {
|
---|
| 56 | p1 = new PointF(left, i);
|
---|
| 57 | p2 = new PointF(right, i);
|
---|
| 58 | g.DrawLine(majorPen, p1, p2);
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | // Draw the major vertical lines, starting at the left edge.
|
---|
| 62 | for (float i = left; i <= right; i += verticalSpacing)
|
---|
| 63 | {
|
---|
| 64 | p1 = new PointF(i, top);
|
---|
| 65 | p2 = new PointF(i, bottom);
|
---|
| 66 | g.DrawLine(majorPen, p1, p2);
|
---|
| 67 | }
|
---|
| 68 | g.ResetClip();
|
---|
| 69 | }
|
---|
| 70 | }
|
---|
| 71 | }
|
---|