表单加载时C#WaitCursor(C# WaitCursor while form loads)

编程入门 行业动态 更新时间:2024-10-20 03:31:33
表单加载时C#WaitCursor(C# WaitCursor while form loads)

我有一个表单,需要几秒钟才能最终显示。 此表单通过以下方式调用:

using (ResultsForm frm = new ResultsForm()) { this.Visible = false; frm.ShowDialog(); this.Visible = true; }

在等待表单最终显示时,我将默认光标移到Cursors.WaitCursor是很有用的。 目前,我似乎只能通过使用静态'Current'属性来成功完成此操作:

using (ResultsForm frm = new ResultsForm()) { //this.Visible = false; Cursor.Current = Cursors.WaitCursor; frm.ShowDialog(); //this.Visible = true; }

但这有两个问题:

它迫使我禁用我想保留的MainForm隐藏功能。 它增加了耦合,因为Cursor.Current = Cursor.Default; 需要在ResultsForm Shown事件中调用。

如何在表单加载时更改光标而不更改第一个代码片段并避免耦合?

更新:现在问题得到解答,视频演示被删除,所以我不会超过我的ISP带宽限制。

I'm having a form that takes a few seconds to finally display. This form is called through:

using (ResultsForm frm = new ResultsForm()) { this.Visible = false; frm.ShowDialog(); this.Visible = true; }

It's useful that I get the default cursor to Cursors.WaitCursor while waiting for the form to finally display. Currently I can only seem to be able to do this successfully by using the static 'Current' property:

using (ResultsForm frm = new ResultsForm()) { //this.Visible = false; Cursor.Current = Cursors.WaitCursor; frm.ShowDialog(); //this.Visible = true; }

But this has two problems:

It forces me to disable the MainForm hiding feature which I would like to retain. It increases coupling since Cursor.Current = Cursor.Default; needs to be called within the ResultsForm Shown event.

How can I change the Cursor while the form loads without changing the first code snippet and while avoiding coupling?

UPDATE: Now the question was answered, video presentation was removed so I don't go over my ISP bandwidth limitations.

最满意答案

你为什么要删除this.Visible = false? 您仍然可以在设置光标时执行此操作。

将ResultsForm设置为光标而不是父窗体是否是可接受的解决方案? 让它在启动始终占用的代码之前设置光标,然后在结束时将其设置回来。

Why do you have to remove the this.Visible = false? You should still be able to do it while setting the cursor.

Would it be an acceptable solution to have the ResultsForm set the cursor instead of the parent form? Get it to set the cursor before it starts the code that takes all the time, then set it back at the end.

更多推荐

本文发布于:2023-07-05 06:58:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1034410.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表单   加载   WaitCursor   form   loads

发布评论

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

>www.elefans.com

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