當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。