如何隐藏form1的同时Application.Run(Form1中)正在执行?Application、Run

2023-09-03 15:11:38 作者:开心的小男人

我有我与运行Form1的 Application.Run

I have a form1 that I run with Application.Run.

我要隐藏这种形式(我需要它隐藏起来,因为我跑一些事情的背景,所以他们必须执行)和一个登录打开另一种形式。

I want to hide this form (I need it hidden because I run some things in the background, so they must execute) and open another form for a log-in.

的方式,我想这是我在Form1构造执行命令 this.Hide(); ,如果登录成功后,显示我Form1上,但它似乎并没有工作。任何想法?

The way I am trying this is by executing in my form1 constructor the command this.Hide(); and if log in is successful, show my form1, but it doesn't seem to work. Any ideas?

推荐答案

只是重写OnVisibleChanged方法,改变在那里形式的知名度,是这样的:

Just override the OnVisibleChanged method and change the visibility of the form in there, something like this:

protected override void OnVisibleChanged(EventArgs e)
{
    base.OnVisibleChanged(e);
    this.Visible = false;
}

这就是它!简单干净。

And that's it! Simple and clean.