.NET screen issues

I have a splash screen for my C # database application that fires through the Shown event. The splash screen contains some information that is pre-processed when the main form constructor is called, so I use the Shown event because this information should be available.

However, when the splash screen is displayed, the main form is crossed out, and the menu bar, lower menu bar, and even the gray background are all white and invisible. It looks like the program is hanging, but after the 5-second delay that I built in, the banner leaves and the program displays normally. In addition, on the banner I have tags that are not displayed when the splash screen is displayed ...

Here is my code, some arguments in favor of why it doesn't work will help a lot.

CLUTCH CONTENT CODE:

public partial class StartupBanner : Form
{
    public StartupBanner(int missingNum, int expiredNum)
    {
        InitializeComponent();
        missingLabel.Text = missingNum.ToString() + " MISSING POLICIES";
        expiredLabel.Text = expiredNum.ToString() + " EXPIRED POLICIES";
    }
}

CALLING CODE:

    private void MainForm_Shown(object sender, EventArgs e)
    {
        StartupBanner startup = new StartupBanner(missingPoliciesNum, expiredPoliciesNum);
        startup.MdiParent = this;
        startup.Show();

        Thread.Sleep(5000);
        startup.Close();
    }

Using startup.ShowDialog () shows the correct information about the shortcuts on the splash screen, but this blocks the application, and I need the splash to go away after about 5 seconds, and that's why it's a splash .;)

+3
source share
4 answers

First, launch the splash screen using ShowDialog () instead of Show (), so the splash screen closes the main form and does not block the main thread:

private void MainForm_Shown(object sender, EventArgs e)
{
    StartupBanner startup = new StartupBanner(missingPoliciesNum, expiredPoliciesNum);
    startup.ShowDialog();
}

In the splash screen form, you must define a timer that closes the form after 5 seconds:

public partial class StartupBanner : Form
{
    private System.Windows.Forms.Timer _closeTimer = new Timer();

    public StartupBanner(int missingNum, int expiredNum)
    {
        this.InitializeComponent();
        missingLabel.Text = missingNum.ToString() + " MISSING POLICIES";
        expiredLabel.Text = expiredNum.ToString() + " EXPIRED POLICIES";

        this._closeTimer = new System.Windows.Forms.Timer();
        this._closeTimer.Interval = 5000;
        this._closeTimer.Tick += new EventHandler(this._closeTimer_Tick);
        this._closeTimer.Start();
    }

    private void _closeTimer_Tick(object sender, EventArgs e)
    {
        System.Windows.Forms.Timer timer = (System.Windows.Forms.Timer)sender;
        timer.Stop();

        this.Close();
    }
}

EDIT: Thread.Sleep() , . , , , . , , .

FIX: startup.MdiParent = this; line

+6

Windows, , . , Windows , , . , . Form.Deactivated.

, , " ". Windows , . " ". , , , . , : " ". , , .

, , .NET.

+2

In your code, MainForm_Shown waits for "Thread.Sleep (5000);", so it got a white color because the main thread was sleeping and could not receive any message. There are several reasons for the StartupBanner Form. I suggest you use Thread to avoid a subfunction or subflow that intercepts the main thread and preempts MainForm.

0
source

There is support for embedded pop-ups in .Net.

The best way and use of the API is

  SplashScreen splash = new SplashScreen("splashscreen.jpg");
  splash.Show(false);
  splash.Close(TimeSpan.FromMilliseconds(2));
  InitializeComponent();
-1
source

Source: https://habr.com/ru/post/1782148/


All Articles