gpt4 book ai didi

C# - 最大化我的表单后,宽度和高度值返回错误

转载 作者:行者123 更新时间:2023-11-30 17:43:06 26 4
gpt4 key购买 nike

我正在通过设置使用全屏

this.WindowState = FormWindowState.Maximized;

执行后,我想获得表单的新宽度和高度,但是当我使用 this.width & this.height 时,它只返回最大化之前设置的值。

这是我的代码:

this.WindowState = FormWindowState.Maximized;
g.DrawImage(app.Properties.Resources.bg, 0, 0, Screen.GetWorkingArea(this).Width, Screen.GetWorkingArea(this).Height);

最佳答案

我无法重现您的问题。我刚刚用一个 Form(最初是 300x300)、一个 Button 和一个 TextBox 制作了一个快速程序。它按预期工作。

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Maximized;
textBox1.Text = this.Width + " " + this.Height;
}
}

我的textBox(textBox1)肯定不显示“300 300”

编辑:根据您更新后的答案和您在下面的评论,试试这个,看看它是否按预期工作(也许还看看手动输入宽度和高度是否有效?):

this.WindowState = FormWindowState.Maximized;
int width = Screen.GetWorkingArea(this).Width;
int height = Screen.GetWorkingArea(this).Height;
g.DrawImage(app.Properties.Resources.bg, 0, 0, width, height);

关于C# - 最大化我的表单后,宽度和高度值返回错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31346276/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com