I'm trying to make a simple game: "Gomoku" or "Five in a Row" in a Windows.Form application.
My program looks like this when is started and I don't press Tab key:
But when I press Tab key it looks like this:
That board is a panel and every time I press Left, Right, Up, Down, A, D, W and S it's moving that two X from corners in the selected direction.
When I was presing Legt and Right it was switching tabPages so I added a textBox and I set focus to him:
if (textBox1.CanFocus)
textBox1.Focus();
This is how I added background color and the lines on the board (game panel.
private void PuneFundal(Graphics g)
{
g.Clear(Color.FromArgb(150, 124, 92));
}
private void DeseneazaLinie(Graphics g, Point p1, Point p2)
{
Pen p = new Pen(Color.Black);
g.DrawLine(p, p1, p2);
}
private void TrasareLinii(Graphics g)
{
for (int i = 6, k = 0; k < 20; i += 16, k++)
DeseneazaLinie(g, new Point(5, i), new Point(309, i));
for (int i = 6, k = 0; k < 20; i += 16, k++)
DeseneazaLinie(g, new Point(i, 5), new Point(i, 309));
}
private void Start_game()
{
tabControl1.SelectedTab = tabPage2;
Graphics g = game_panel.CreateGraphics();
PuneFundal(g);
TrasareLinii(g);
}
What can I do to work well when I press Tab key?