当前位置: 首页>>代码示例>>C#>>正文


C# GroupBox.CreateGraphics方法代码示例

本文整理汇总了C#中System.Windows.Forms.GroupBox.CreateGraphics方法的典型用法代码示例。如果您正苦于以下问题:C# GroupBox.CreateGraphics方法的具体用法?C# GroupBox.CreateGraphics怎么用?C# GroupBox.CreateGraphics使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Forms.GroupBox的用法示例。


在下文中一共展示了GroupBox.CreateGraphics方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DrawMaze

        public void DrawMaze(GroupBox canvas)
        {
            Pen myPen = new System.Drawing.Pen(Color.Red);
            SolidBrush mBrush = new SolidBrush(Color.LawnGreen);
            Graphics fGraphics = canvas.CreateGraphics();
            fGraphics.Clear(Color.Gray);

            Random rand = new Random();

            startPosition = new Point(rand.Next(0, width), rand.Next(0, height));
            finalDestination = new Point(rand.Next(0, width), rand.Next(0, height));

            int size = 20;
            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    MazeCell currCell = maze[i][j];

                    if (currCell.North == null)
                        fGraphics.DrawLine(myPen, i * size, j * size, (i + 1) * size, j * size);

                    if (currCell.South == null)
                        fGraphics.DrawLine(myPen, i * size, (j + 1) * size, (i + 1) * size, (j + 1) * size);

                    if (currCell.East == null)
                        fGraphics.DrawLine(myPen, (i + 1) * size, j * size, (i + 1) * size, (j + 1) * size);

                    if (currCell.West == null)
                        fGraphics.DrawLine(myPen, i * size, j * size, i * size, (j + 1) * size);
                }
            }

            //drawing startin and ending point
            fGraphics.FillRectangle(mBrush, startPosition.X * size + size / 2, startPosition.Y * size + size / 2, size / 2, size / 2);
            mBrush.Color = Color.SteelBlue;
            fGraphics.FillRectangle(mBrush, finalDestination.X * size + size / 2, finalDestination.Y * size + size / 2, size / 2, size / 2);

            myPen.Dispose();
            fGraphics.Dispose();
            mBrush.Dispose();
        }
开发者ID:obllivion,项目名称:MazeGenerator,代码行数:42,代码来源:Generator.cs


注:本文中的System.Windows.Forms.GroupBox.CreateGraphics方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。