Ejemplo n.º 1
0
        internal static void DrawGrid(Graphics graphics, Rectangle viewableRectangle)
        {
            AmbientTheme ambientTheme = WorkflowTheme.CurrentTheme.AmbientTheme;
            if (ambientTheme.GridStyle == DashStyle.Dot)
            {
                Point gridStart = Point.Empty;
                gridStart.X = viewableRectangle.X - (viewableRectangle.X % ambientTheme.GridSize.Width);
                gridStart.Y = viewableRectangle.Y - (viewableRectangle.Y % ambientTheme.GridSize.Height);

                for (int gridCoOrdX = gridStart.X; gridCoOrdX <= viewableRectangle.Right; gridCoOrdX += Math.Max(ambientTheme.GridSize.Width, 1))
                {
                    for (int gridCoOrdY = gridStart.Y; gridCoOrdY <= viewableRectangle.Bottom; gridCoOrdY += Math.Max(ambientTheme.GridSize.Height, 1))
                    {
                        graphics.FillRectangle(ambientTheme.MajorGridBrush, new Rectangle(new Point(gridCoOrdX, gridCoOrdY), new Size(1, 1)));

                        if (((gridCoOrdX + ambientTheme.GridSize.Width / 2) >= viewableRectangle.Left && (gridCoOrdX + ambientTheme.GridSize.Width / 2) <= viewableRectangle.Right) &&
                            ((gridCoOrdY + ambientTheme.GridSize.Height / 2) >= viewableRectangle.Top && (gridCoOrdY + ambientTheme.GridSize.Height / 2) <= viewableRectangle.Bottom))
                            graphics.FillRectangle(ambientTheme.MinorGridBrush, new Rectangle(new Point(gridCoOrdX + ambientTheme.GridSize.Width / 2, gridCoOrdY + ambientTheme.GridSize.Height / 2), new Size(1, 1)));
                    }
                }
            }
            else
            {
                //We use native pens to draw the grid for efficiency reason
                using (Hdc hdc = new Hdc(graphics))
                using (HPen majorGridPen = new HPen(ambientTheme.MajorGridPen))
                using (HPen minorGridPen = new HPen(ambientTheme.MinorGridPen))
                {
                    hdc.DrawGrid(majorGridPen, minorGridPen, viewableRectangle, ambientTheme.GridSize, true);
                }
            }
        }
 internal static void DrawGrid(Graphics graphics, Rectangle viewableRectangle)
 {
     AmbientTheme ambientTheme = WorkflowTheme.CurrentTheme.AmbientTheme;
     if (ambientTheme.GridStyle == DashStyle.Dot)
     {
         Point empty = Point.Empty;
         empty.X = viewableRectangle.X - (viewableRectangle.X % ambientTheme.GridSize.Width);
         empty.Y = viewableRectangle.Y - (viewableRectangle.Y % ambientTheme.GridSize.Height);
         for (int i = empty.X; i <= viewableRectangle.Right; i += Math.Max(ambientTheme.GridSize.Width, 1))
         {
             for (int j = empty.Y; j <= viewableRectangle.Bottom; j += Math.Max(ambientTheme.GridSize.Height, 1))
             {
                 graphics.FillRectangle(ambientTheme.MajorGridBrush, new Rectangle(new Point(i, j), new Size(1, 1)));
                 if ((((i + (ambientTheme.GridSize.Width / 2)) >= viewableRectangle.Left) && ((i + (ambientTheme.GridSize.Width / 2)) <= viewableRectangle.Right)) && (((j + (ambientTheme.GridSize.Height / 2)) >= viewableRectangle.Top) && ((j + (ambientTheme.GridSize.Height / 2)) <= viewableRectangle.Bottom)))
                 {
                     graphics.FillRectangle(ambientTheme.MinorGridBrush, new Rectangle(new Point(i + (ambientTheme.GridSize.Width / 2), j + (ambientTheme.GridSize.Height / 2)), new Size(1, 1)));
                 }
             }
         }
     }
     else
     {
         using (Hdc hdc = new Hdc(graphics))
         {
             using (HPen pen = new HPen(ambientTheme.MajorGridPen))
             {
                 using (HPen pen2 = new HPen(ambientTheme.MinorGridPen))
                 {
                     hdc.DrawGrid(pen, pen2, viewableRectangle, ambientTheme.GridSize, true);
                 }
             }
         }
     }
 }
Ejemplo n.º 3
0
            //internal void DrawLines(HPen pen, Point[] points)
            //{
            //    try
            //    {
            //        IntPtr objectPtr = NativeMethods.SelectObject(this.hdc, pen.Handle);
            //        if (objectPtr == IntPtr.Zero)
            //            throw new Win32Exception(Marshal.GetLastWin32Error());

            //        if (!NativeMethods.MoveToEx(this.hdc, points[0].X, points[0].Y, null))
            //            throw new Win32Exception(Marshal.GetLastWin32Error());

            //        for (int i = 0; i < points.Length - 1; i++)
            //        {
            //            if (!NativeMethods.LineTo(this.hdc, points[i + 1].X, points[i + 1].Y))
            //                throw new Win32Exception(Marshal.GetLastWin32Error());
            //        }
            //    }
            //    finally
            //    {
            //        IntPtr objectPtr = NativeMethods.SelectObject(this.hdc, this.oldPen);
            //        if (objectPtr == IntPtr.Zero)
            //            throw new Win32Exception(Marshal.GetLastWin32Error());
            //    }
            //}

            internal void DrawGrid(HPen majorGridPen, HPen minorGridPen, Rectangle viewableRectangle, Size gridUnit, bool showMinorGrid)
            {
                try
                {
                    Point gridStart = Point.Empty;
                    gridStart.X = viewableRectangle.X - (viewableRectangle.X % gridUnit.Width);
                    gridStart.Y = viewableRectangle.Y - (viewableRectangle.Y % gridUnit.Height);
                    IntPtr objectPtr = NativeMethods.SelectObject(this.hdc, majorGridPen.Handle);
                    if (objectPtr == IntPtr.Zero)
                        throw new Win32Exception(Marshal.GetLastWin32Error());

                    for (int gridCoOrd = gridStart.X; gridCoOrd <= viewableRectangle.Right; gridCoOrd += Math.Max(gridUnit.Width, 1))
                    {
                        if (gridCoOrd >= viewableRectangle.Left)
                        {
                            if (!NativeMethods.MoveToEx(this.hdc, gridCoOrd, viewableRectangle.Top + 1, null))
                                throw new Win32Exception(Marshal.GetLastWin32Error());

                            if (!NativeMethods.LineTo(this.hdc, gridCoOrd, viewableRectangle.Bottom - 1))
                                throw new Win32Exception(Marshal.GetLastWin32Error());
                        }

                        if (showMinorGrid && (gridCoOrd + gridUnit.Width / 2) >= viewableRectangle.Left && (gridCoOrd + gridUnit.Width / 2) <= viewableRectangle.Right)
                        {
                            objectPtr = NativeMethods.SelectObject(this.hdc, minorGridPen.Handle);
                            if (objectPtr == IntPtr.Zero)
                                throw new Win32Exception(Marshal.GetLastWin32Error());

                            if (!NativeMethods.MoveToEx(this.hdc, gridCoOrd + gridUnit.Width / 2, viewableRectangle.Top + 1, null))
                                throw new Win32Exception(Marshal.GetLastWin32Error());

                            if (!NativeMethods.LineTo(this.hdc, gridCoOrd + gridUnit.Width / 2, viewableRectangle.Bottom - 1))
                                throw new Win32Exception(Marshal.GetLastWin32Error());

                            objectPtr = NativeMethods.SelectObject(this.hdc, majorGridPen.Handle);
                            if (objectPtr == IntPtr.Zero)
                                throw new Win32Exception(Marshal.GetLastWin32Error());
                        }
                    }

                    for (int gridCoOrd = gridStart.Y; gridCoOrd <= viewableRectangle.Bottom; gridCoOrd += Math.Max(gridUnit.Height, 1))
                    {
                        if (gridCoOrd >= viewableRectangle.Top)
                        {
                            if (!NativeMethods.MoveToEx(this.hdc, viewableRectangle.Left + 1, gridCoOrd, null))
                                throw new Win32Exception(Marshal.GetLastWin32Error());

                            if (!NativeMethods.LineTo(this.hdc, viewableRectangle.Right - 1, gridCoOrd))
                                throw new Win32Exception(Marshal.GetLastWin32Error());
                        }

                        if (showMinorGrid && (gridCoOrd + gridUnit.Height / 2) >= viewableRectangle.Top && (gridCoOrd + gridUnit.Height / 2) <= viewableRectangle.Bottom)
                        {
                            objectPtr = NativeMethods.SelectObject(this.hdc, minorGridPen.Handle);
                            if (objectPtr == IntPtr.Zero)
                                throw new Win32Exception(Marshal.GetLastWin32Error());

                            if (!NativeMethods.MoveToEx(this.hdc, viewableRectangle.Left + 1, gridCoOrd + gridUnit.Height / 2, null))
                                throw new Win32Exception(Marshal.GetLastWin32Error());

                            if (!NativeMethods.LineTo(this.hdc, viewableRectangle.Right - 1, gridCoOrd + gridUnit.Height / 2))
                                throw new Win32Exception(Marshal.GetLastWin32Error());

                            objectPtr = NativeMethods.SelectObject(this.hdc, majorGridPen.Handle);
                            if (objectPtr == IntPtr.Zero)
                                throw new Win32Exception(Marshal.GetLastWin32Error());

                        }
                    }
                }
                finally
                {
                    IntPtr objectPtr = NativeMethods.SelectObject(this.hdc, this.oldPen);
                    if (objectPtr == IntPtr.Zero)
                        throw new Win32Exception(Marshal.GetLastWin32Error());

                }
            }