C# 在Windows窗体中调整活动窗体的大小

C# 在Windows窗体中调整活动窗体的大小,c#,.net,winforms,C#,.net,Winforms,这就是游戏,如果你能抓住我。 目前大小是静态的。我们只能在静态高度/宽度下玩游戏。 当WindowsForm的大小设置为最大值时,如何创建按钮转到不同的坐标? 抱歉解释得不好,希望你能理解:S public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { button1.MouseEnter += button1_MouseEnter; bu

这就是游戏,如果你能抓住我。 目前大小是静态的。我们只能在静态高度/宽度下玩游戏。 当WindowsForm的大小设置为最大值时,如何创建按钮转到不同的坐标? 抱歉解释得不好,希望你能理解:S

public Form1()
{
    InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
    button1.MouseEnter += button1_MouseEnter;
    button1.BackColor = Color.AliceBlue;
    button1.Text = "Noķer";
}

private void button1_Click(object sender, EventArgs e)
{
    button1.MouseEnter -= button1_MouseEnter;
    button1.Text = "gatavs";
    button1.BackColor = Color.Aquamarine;

}

private void button1_MouseEnter(object sender, EventArgs e)
{
    Random rnd = new Random();
    button1.Location = new Point(rnd.Next(12, 197), rnd.Next(12, 226));
}

如果我明白你想说什么,你可以用点法传递表单的实际大小,如下所示:

button1.Location = new Point(rnd.Next(12, this.Size.Height), rnd.Next(12, this.Size.Width));

祝你好运

如果我明白你想说什么,你可以用点法传递表单的实际大小,如下所示:

button1.Location = new Point(rnd.Next(12, this.Size.Height), rnd.Next(12, this.Size.Width));

祝你好运

如果我明白你想说什么,你可以用点法传递表单的实际大小,如下所示:

button1.Location = new Point(rnd.Next(12, this.Size.Height), rnd.Next(12, this.Size.Width));

祝你好运

如果我明白你想说什么,你可以用点法传递表单的实际大小,如下所示:

button1.Location = new Point(rnd.Next(12, this.Size.Height), rnd.Next(12, this.Size.Width));
祝你好运

使用以下命令:

private void button1_MouseEnter(object sender, EventArgs e)
{
    Random rnd = new Random();
    button1.Location = new Point(
         rnd.Next(0, this.ClientRectangle.Width- this.button1.Width),
         rnd.Next(0,this.ClientRectangle.Height- this.button1.Height));
}
这样,您将确保按钮永远不会超出窗体边界。如果不从最大宽度和高度中减去按钮宽度和高度,则按钮的某些部分可能会超出窗体边框。

使用以下方法:

private void button1_MouseEnter(object sender, EventArgs e)
{
    Random rnd = new Random();
    button1.Location = new Point(
         rnd.Next(0, this.ClientRectangle.Width- this.button1.Width),
         rnd.Next(0,this.ClientRectangle.Height- this.button1.Height));
}
这样,您将确保按钮永远不会超出窗体边界。如果不从最大宽度和高度中减去按钮宽度和高度,则按钮的某些部分可能会超出窗体边框。

使用以下方法:

private void button1_MouseEnter(object sender, EventArgs e)
{
    Random rnd = new Random();
    button1.Location = new Point(
         rnd.Next(0, this.ClientRectangle.Width- this.button1.Width),
         rnd.Next(0,this.ClientRectangle.Height- this.button1.Height));
}
这样,您将确保按钮永远不会超出窗体边界。如果不从最大宽度和高度中减去按钮宽度和高度,则按钮的某些部分可能会超出窗体边框。

使用以下方法:

private void button1_MouseEnter(object sender, EventArgs e)
{
    Random rnd = new Random();
    button1.Location = new Point(
         rnd.Next(0, this.ClientRectangle.Width- this.button1.Width),
         rnd.Next(0,this.ClientRectangle.Height- this.button1.Height));
}

这样,您将确保按钮永远不会超出窗体边界。如果不从最大宽度和高度中减去按钮宽度和高度,则按钮的某些部分可能会超出窗体边框。

这与我想要的接近,但您可以自己尝试代码,看到按钮消失且无法正常工作这与我想要的接近,但是你可以自己尝试代码,看到按钮消失,不能正常工作这是接近我想要的东西,但是你可以自己尝试代码,看到按钮消失,不能正常工作这是接近我想要的东西,但是你可以自己尝试代码,看到按钮消失了,不能正常工作。谢谢,正是我需要的:谢谢,正是我需要的:谢谢,正是我需要的:谢谢,正是我需要的:谢谢,正是我需要的:P