Шахматная доска на C# в visual studio 2010

Узнай цену своей работы

Формулировка задачи:

Помогите, пожалуйста, решить задачу: Выведите на форму, используя класс Graphics, шахматную доску. Ну и чтобы соответственно по бокам были пронумерованы поля, и буквы поставлены. Нужно на языке C# в Visual Studio 2010. Нужно только, чтобы выводилась доска=) фигурки и тд и тп не нужно.

Решение задачи: «Шахматная доска на C# в visual studio 2010»

textual
Листинг программы
public partial class Form1 : Form
    {
        const int RECT = 32;
        char[] SYMBOL = "abcdefgh".ToCharArray();
        int[] HorseCourseX = { -1, 1, 2, 2, 1, -1, -2, -2 };
        int[] HorseCourseY = { -2, -2, -1, 1, 2, 2, 1, -1 };
 
        Graphics graph;
        SolidBrush brushWhite = new SolidBrush(Color.White);
        SolidBrush brushBlack = new SolidBrush(Color.Black);
        SolidBrush brushRed = new SolidBrush(Color.Red);
        Pen penBlack = new Pen(Color.Black);
        Font font = new Font("Arial", 18);
       
        public Form1()
        {
            InitializeComponent();
            graph = pnGraphic.CreateGraphics();
        }
 
        void DrawTable()
        {
            Boolean squareColor = true;
            for (int i = 1; i < 9; i++)
            {
                squareColor = !squareColor;
                for (int j = 1; j < 9; j++)
                {
                    squareColor = !squareColor;
                    if (squareColor)
                        graph.FillRectangle(brushWhite, j * RECT, i * RECT, RECT, RECT);
                    else
                        graph.FillRectangle(brushBlack, j * RECT, i * RECT, RECT, RECT);
                }
            }
            graph.DrawRectangle(penBlack, RECT, RECT, RECT * 8, RECT * 8);
 
            for (int i = 1; i < 9; i++)
            {
                graph.DrawString(SYMBOL[i - 1].ToString(), font, brushBlack, i * RECT + 6, 5);
                graph.DrawString((9 - i).ToString(), font, brushBlack, 10, i * RECT + 6);
            }
        }    
                private void Form1_Load(object sender, EventArgs e)
        {
            DrawTable();
        }
 
                private void pnGraphic_Paint(object sender, PaintEventArgs e)
                {
 
                }
    }
}

Оцени полезность:

13   голосов , оценка 3.692 из 5