闪屏问题 - C# - VS2005

发布于 2024-07-10 15:32:06 字数 176 浏览 4 评论 0原文

我有一个申请。

首先,我显示一个启动画面,一个表单,这个启动画面将调用另一个表单。

问题:当显示启动画面时,如果我在启动画面顶部打开另一个应用程序,然后最小化这个新打开的应用程序窗口,启动画面会变成白色。 我该如何避免这种情况? 我希望我的启动画面能够清晰显示,并且不受任何应用程序的影响。

I have an application.

First I display a splash screen, a form, and this splash would call another form.

Problem: When the splash form is displayed, if I then open another application on the top of the splash, and then minimize this newly opened application window, the splash screen becomes white. How do I avoid this? I want my splash to be displayed clearly and not affected by any application.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

失眠症患者 2024-07-17 15:32:06

您需要在不同的线程中显示启动屏幕 - 当前您的新表单加载代码正在阻塞启动屏幕的 UI 线程。

启动一个新线程,并在该线程上创建启动屏幕并调用 Application.Run(splash)。 这将在该线程上启动一个新的消息泵。 然后,您需要在准备就绪时将主 UI 线程回调到初始屏幕的 UI 线程(例如使用 Control.Invoke/BeginInvoke),以便初始屏幕可以自行关闭。

重要的是确保您不会尝试从错误的线程修改 UI 控件 - 仅使用创建该控件的线程。

You need to display the splash screen in a different thread - currently your new form loading code is blocking the splash screen's UI thread.

Start a new thread, and on that thread create your splash screen and call Application.Run(splash). That will start a new message pump on that thread. You'll then need to make your main UI thread call back to the splash screen's UI thread (e.g. with Control.Invoke/BeginInvoke) when it's ready, so the splash screen can close itself.

The important thing is to make sure that you don't try to modify a UI control from the wrong thread - only use the one the control was created on.

纸伞微斜 2024-07-17 15:32:06

.NET 框架对闪屏具有出色的内置支持。 启动一个新的WF项目,Project + Add Reference,选择Microsoft.VisualBasic。 添加一个新表单,将其命名为 frmSplash。 打开 Project.cs 并使其看起来像这样:

using System;
using System.Windows.Forms;
using Microsoft.VisualBasic.ApplicationServices;

namespace WindowsFormsApplication1 {
  static class Program {
    [STAThread]
    static void Main(string[] args) {
      Application.EnableVisualStyles();
      Application.SetCompatibleTextRenderingDefault(false);
      new MyApp().Run(args);
    }
  }
  class MyApp : WindowsFormsApplicationBase {
    protected override void OnCreateSplashScreen() {
      this.SplashScreen = new frmSplash();
    }
    protected override void OnCreateMainForm() {
      // Do your time consuming stuff here...
      //...
      System.Threading.Thread.Sleep(3000);
      // Then create the main form, the splash screen will close automatically
      this.MainForm = new Form1();
    }
  }
}

The .NET framework has excellent built-in support for splash screens. Start a new WF project, Project + Add Reference, select Microsoft.VisualBasic. Add a new form, call it frmSplash. Open Project.cs and make it look like this:

using System;
using System.Windows.Forms;
using Microsoft.VisualBasic.ApplicationServices;

namespace WindowsFormsApplication1 {
  static class Program {
    [STAThread]
    static void Main(string[] args) {
      Application.EnableVisualStyles();
      Application.SetCompatibleTextRenderingDefault(false);
      new MyApp().Run(args);
    }
  }
  class MyApp : WindowsFormsApplicationBase {
    protected override void OnCreateSplashScreen() {
      this.SplashScreen = new frmSplash();
    }
    protected override void OnCreateMainForm() {
      // Do your time consuming stuff here...
      //...
      System.Threading.Thread.Sleep(3000);
      // Then create the main form, the splash screen will close automatically
      this.MainForm = new Form1();
    }
  }
}
夜清冷一曲。 2024-07-17 15:32:06

我有一个类似的问题,你可能想检查一下。 我的 Stack Overflow 答案 非常适合我 - 你可能想要采纳看看。

I had a similar issue you might want to check out. The Stack Overflow answer I got worked perfectly for me - you may want to take a look.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文