C#:显示不可见的形式 [英] C#: showing an invisible form
问题描述
我在C#中具有以下代码:
I have the following code in C#:
Form f = new MyForm();
f.Visible = false;
f.Show();
f.Close();
尽管f.Visible = false
,我看到的是闪烁的形式出现然后消失.我需要怎么做才能使此表单不可见?
Despite the f.Visible = false
, I am seeing a flash of the form appearing and then disappearing. What do I need to do to make this form invisible?
我需要在启动应用程序时(不可见地)显示该表单,因为这样做可以消除显示此表单时的冷启动延迟.
I need to show the form (invisibly) during the splash of my app because doing this removes a cold start delay when showing this form.
推荐答案
如果要显示表单而不实际看到它,可以执行以下操作:
If you want to show the form without actually seeing it, you can do this:
public Form1()
{
InitializeComponent();
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.ShowInTaskbar = false;
this.Load += new EventHandler(Form1_Load);
}
void Form1_Load(object sender, EventArgs e)
{
this.Size = new Size(0, 0);
}
如果以后要显示它,则只需将所有内容改回即可.这是一个10秒钟后的示例,它显示了以下形式:
If at a later point you want to show it, you can just change everything back. Here is an example after 10 seconds, it shows the form:
Timer tmr = new Timer();
public Form1()
{
tmr.Interval = 10000;
tmr.Tick += new EventHandler(tmr_Tick);
tmr.Start();
InitializeComponent();
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.ShowInTaskbar = false;
this.Load += new EventHandler(Form1_Load);
}
void tmr_Tick(object sender, EventArgs e)
{
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable;
this.ShowInTaskbar = true;
this.Size = new Size(300, 300);
}
void Form1_Load(object sender, EventArgs e)
{
this.Size = new Size(0, 0);
}
这篇关于C#:显示不可见的形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!