C#:显示不可见的形式

编程入门 行业动态 更新时间:2024-10-25 14:34:35
本文介绍了C#:显示不可见的形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在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#:显示不可见的形式

本文发布于:2023-10-18 11:28:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1504099.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:形式

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!