Free cookie consent management tool by TermsFeed Policy Generator

source: tags/3.3.3/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/Core/Grid.cs @ 5447

Last change on this file since 5447 was 4068, checked in by swagner, 14 years ago

Sorted usings and removed unused usings in entire solution (#1094)

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