Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/Core/Grid.cs @ 2768

Last change on this file since 2768 was 2768, checked in by mkommend, 14 years ago

added solution folders and sources for the netron library (ticket #867)

File size: 2.4 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.Drawing;
5using System.Windows.Forms;
6using System.Drawing.Drawing2D;
7
8namespace 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}
Note: See TracBrowser for help on using the repository browser.