gpt4 book ai didi

C# 按钮文本和调整大小

转载 作者:太空宇宙 更新时间:2023-11-03 17:23:00 24 4
gpt4 key购买 nike

我有一个简单的按钮,单击该按钮时应将文本从“帮助”更改为“隐藏”以及窗口窗体大小。我遇到的问题是找不到 if 语句。它看不到 button3.text 帮助或隐藏。有什么提示或建议吗?

private void button2_Click(object sender, EventArgs e)
{
string helpstring = "Help";
string hidestring = "Hide";
if (button3.Text == helpstring)
{
button3.Text = hidestring;
Size = new System.Drawing.Size(1106, 563);
}
if (button3.Text == "Hide")
{
Size = new System.Drawing.Size(586, 563);
button3.Text = helpstring;
}
}

最佳答案

您忘记了“else”。这应该有效:

private void button2_Click(object sender, EventArgs e)
{
string helpstring = "Help";
string hidestring = "Hide";
if (button3.Text == helpstring)
{
button3.Text = hidestring;
Size = new System.Drawing.Size(1106, 563);
}
else if (button3.Text == "Hide") //this is where you should put an else
{
Size = new System.Drawing.Size(586, 563);
button3.Text = helpstring;
}
}

关于C# 按钮文本和调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2006783/

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