SampleApp.MainForm.mapPanel_Paint C# (CSharp) Method

mapPanel_Paint() private method

private mapPanel_Paint ( object sender, System e ) : void
sender object
e System
return void
        private void mapPanel_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            if (map != null)
            {
                //
                bool showConnections = showConnectionsCheck.Checked;
                bool showInactive = showInactiveCheck.Checked;

                // pens and brushes
                Brush brush = new SolidBrush(Color.Blue);
                Brush brushGray = new SolidBrush(Color.FromArgb(192, 192, 192));
                Pen pen = new Pen(Color.Blue, 1);
                Pen penGray = new Pen(Color.FromArgb(192, 192, 192), 1);

                // lock
                Monitor.Enter(this);

                if (showConnections)
                {
                    // draw connections
                    for (int i = 0, n = map.GetLength(0); i < n; i++)
                    {
                        for (int j = 0, k = map.GetLength(1); j < k; j++)
                        {
                            if ((!showInactive) && (map[i, j, 2] == 0))
                                continue;

                            // left
                            if ((i > 0) && ((showInactive) || (map[i - 1, j, 2] == 1)))
                            {
                                g.DrawLine(((map[i, j, 2] == 0) || (map[i - 1, j, 2] == 0)) ? penGray : pen, map[i, j, 0], map[i, j, 1], map[i - 1, j, 0], map[i - 1, j, 1]);
                            }

                            // right
                            if ((i < n - 1) && ((showInactive) || (map[i + 1, j, 2] == 1)))
                            {
                                g.DrawLine(((map[i, j, 2] == 0) || (map[i + 1, j, 2] == 0)) ? penGray : pen, map[i, j, 0], map[i, j, 1], map[i + 1, j, 0], map[i + 1, j, 1]);
                            }

                            // top
                            if ((j > 0) && ((showInactive) || (map[i, j - 1, 2] == 1)))
                            {
                                g.DrawLine(((map[i, j, 2] == 0) || (map[i, j - 1, 2] == 0)) ? penGray : pen, map[i, j, 0], map[i, j, 1], map[i, j - 1, 0], map[i, j - 1, 1]);
                            }

                            // bottom
                            if ((j < k - 1) && ((showInactive) || (map[i, j + 1, 2] == 1)))
                            {
                                g.DrawLine(((map[i, j, 2] == 0) || (map[i, j + 1, 2] == 0)) ? penGray : pen, map[i, j, 0], map[i, j, 1], map[i, j + 1, 0], map[i, j + 1, 1]);
                            }
                        }
                    }
                }

                // draw the map
                for (int i = 0, n = map.GetLength(0); i < n; i++)
                {
                    for (int j = 0, k = map.GetLength(1); j < k; j++)
                    {
                        if ((!showInactive) && (map[i, j, 2] == 0))
                            continue;

                        // draw the point
                        g.FillEllipse((map[i, j, 2] == 0) ? brushGray : brush, map[i, j, 0] - 2, map[i, j, 1] - 2, 5, 5);
                    }
                }

                // unlock
                Monitor.Exit(this);

                brush.Dispose();
                brushGray.Dispose();
                pen.Dispose();
                penGray.Dispose();
            }
        }
MainForm