gpt4 book ai didi

c# - 从.Hide() 改成.Show() 的窗体无法最大化,为什么?

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

我编写了一个隐藏或显示所有应用程序形式(包括子形式)的方法。代码如下:

public enum FormState
{
Show ,
Hidden,
Enable,
Disable
}

private void SetAllFormsState(FormState formState)
{
FormCollection forms = Application.OpenForms;
FormWindowState formWinState;
bool state;

if (formState == FormState.Show)
{
formWinState = FormWindowState.Normal;
state = true;
}
else if (formState == FormState.Hidden)
{
formWinState = FormWindowState.Minimized;
state = false;
}
else
{
throw new ArgumentNullException("invalid flag");
}

for (int i = forms.Count - 1; i >= 0; i--)
{
Form form = forms[i];
form.WindowState = formWinState;

if (state)
{
form.Show();
}
else
{
form.Hide();
}
}
}

但是当我再次调用表单时:

SetAllFormsState(FormState.Show);

只能选择父窗体。子窗体显示在窗口/任务栏中,但似乎被窗口“锁定”,无法最大化或更改为正常样式。我该如何解决?

最佳答案

尝试在Show()Hide() 方法调用之后 设置form.WindowState:

for (int i = forms.Count - 1; i >= 0; i--)
{
Form form = forms[i];
if (state)
{
form.Show();
}
else
{
form.Hide();
}
form.WindowState = formWinState;
}

关于c# - 从.Hide() 改成.Show() 的窗体无法最大化,为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8655739/

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