按钮文字没有出现c#

时间:2018-02-26 19:08:58

标签: c# winforms

我正在使用Windows窗体(System.Windows.Forms)编写国际象棋游戏程序,我创建了一个按钮来开始新游戏。由于某种原因,按钮应显示的文本根本不显示。除此之外,按钮功能非常好。

我该如何解决?

代码:

using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Chess.Properties;

public class Form1 : Form
{
    PictureBox[,] tiles = new PictureBox[8, 8];
    Button newGame = new Button();
    public Form1()
    {
        this.MinimumSize = new Size(560, 519);
        this.MaximumSize = new Size(560, 519);
        newGame.Click += new EventHandler(newGame_Click);
        newGame.Size = new Size(560, 519);
        newGame.Location = new Point(481, 0);
        newGame.Text = "New Game";
        newGame.Font = new Font(FontFamily.GenericSansSerif, 24.0f, FontStyle.Bold);
        this.Controls.Add(newGame);
        for (int x = 0; x < 8; x++)
            for (int y = 0; y < 8; y++)
            {
                tiles[x, y] = new PictureBox();
                tiles[x, y].Size = new Size(60, 60);
                tiles[x, y].Location = new Point(x * 60, y * 60);
                tiles[x, y].Name = "";
                this.Controls.Add(tiles[x, y]);
                if (x == 0)
                    if (y % 2 == 0)
                        tiles[x, y].BackColor = Color.Gray;
                    else tiles[x, y].BackColor = Color.White;
                else if (tiles[x - 1, y].BackColor == Color.Gray)
                    tiles[x, y].BackColor = Color.White;
                else tiles[x, y].BackColor = Color.Gray;
            }
    }

    void newGame_Click(Object sender, EventArgs e)
    {
        //Initial White Pieces
        tiles[0, 0].Image = Resources.wTower;
        tiles[0, 1].Image = Resources.wHorse;
        tiles[0, 2].Image = Resources.wRunner;
        tiles[0, 3].Image = Resources.wQueen;
        tiles[0, 4].Image = Resources.wKing;
        tiles[0, 5].Image = Resources.wRunner;
        tiles[0, 6].Image = Resources.wHorse;
        tiles[0, 7].Image = Resources.wTower;
        tiles[0, 0].Name = "wTower";
        tiles[0, 1].Name = "wHorse";
        tiles[0, 2].Name = "wRunner";
        tiles[0, 3].Name = "wQueen";
        tiles[0, 4].Name = "wKing";
        tiles[0, 5].Name = "wRunner";
        tiles[0, 6].Name = "wHorse";
        tiles[0, 7].Name = "wTower";
        for(int i = 0; i < 8; i++)
        {
            tiles[1, i].Image = Resources.wSoldier;
            tiles[1, i].Name = "wSoldier";
        }
        //Initial Black Pieces
        tiles[7, 0].Image = Resources.bTower;
        tiles[7, 1].Image = Resources.bHorse;
        tiles[7, 2].Image = Resources.bRunner;
        tiles[7, 3].Image = Resources.bQueen;
        tiles[7, 4].Image = Resources.bKing;
        tiles[7, 5].Image = Resources.bRunner;
        tiles[7, 6].Image = Resources.bHorse;
        tiles[7, 7].Image = Resources.bTower;
        tiles[7, 0].Name = "bTower";
        tiles[7, 1].Name = "bHorse";
        tiles[7, 2].Name = "bRunner";
        tiles[7, 3].Name = "bQueen";
        tiles[7, 4].Name = "bKing";
        tiles[7, 5].Name = "bRunner";
        tiles[7, 6].Name = "bHorse";
        tiles[7, 7].Name = "bTower";
        for (int i = 0; i < 8; i++)
        {
            tiles[6, i].Image = Resources.bSoldier;
            tiles[6, i].Name = "bSoldier";
        }
    }

    [STAThread]
    static void Main()
    {
        Application.Run(new Form1());
    }
}

资源: My resources

1 个答案:

答案 0 :(得分:0)

你的按钮很大,你只看到它的左侧部分,它排除了带有文字的部分。请尝试将此用作按钮大小:

        newGame.Size = new Size(60, 519);