Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在我的面板顶部放置按钮?_C#_Winforms - Fatal编程技术网

C# 如何在我的面板顶部放置按钮?

C# 如何在我的面板顶部放置按钮?,c#,winforms,C#,Winforms,如何使用C#代码在面板顶部放置按钮 这将在panel1上添加button1,您希望按钮实际位于面板上,还是位于面板上方的窗体上?查尔斯:是的,我想要面板上的按钮。 public partial class SpaceExplorer : Form { Button btnPlayer = new Button(); Panel pGame = new Panel(); public SpaceExplorer() { InitializeComp

如何使用C#代码在面板顶部放置按钮


这将在
panel1

上添加
button1
,您希望按钮实际位于面板上,还是位于面板上方的窗体上?查尔斯:是的,我想要面板上的按钮。
public partial class SpaceExplorer : Form
{
    Button btnPlayer = new Button();
    Panel pGame = new Panel();

    public SpaceExplorer()
    {
        InitializeComponent();

        // panel: pGame
        pGame.BackColor = System.Drawing.Color.Black;
        pGame.Dock = System.Windows.Forms.DockStyle.Fill;
        pGame.Location = new System.Drawing.Point(0, 24);
        pGame.Name = "panelMain";

        Controls.Add(pGame);
    }

    private void subMenuStart_Click(object sender, EventArgs e)
    {
        // button: btnPlayer
        btnPlayer.Location = new System.Drawing.Point(0, 23);
        btnPlayer.Name = "player";
        btnPlayer.Size = new System.Drawing.Size(20, 20);
        btnPlayer.BackColor = Color.White;
        btnPlayer.Text = string.Empty;
        btnPlayer.Enabled = false;

        Controls.Add(btnPlayer);
    }
}
        this.button1.Location = new System.Drawing.Point(0, 0);
        this.button1.Name = "button1";
        this.button1.Size = new System.Drawing.Size(75, 23);
        this.button1.TabIndex = 0;
        this.button1.Text = "button1";
        this.button1.UseVisualStyleBackColor = true;
        panel1.Controls.Add(button1);