English 中文(简体)
1. screen
原标题:Making a splash screen

闪电屏幕的概念对我来说是一种应该如此复杂的事,但我有麻烦地把整个闪电屏幕涂上。

请允许我说,我有两条<代码>System.WindowsForms.Forms: RealForm and SplashScreen。 真正论坛包含最初的全球倡议。 在ReForm装载过程中(即,如果是<代码>Load的投稿人),ReForm与数据库建立了联系,然后对链接进行测试。 这可能需要几秒钟,因此,在我完成这一切之前,我试图像这样扔下一个大刀:

private void RealForm_Load(object sender, EventArgs e)
{
    SplashScreen splash = new SplashScreen();
    splash.Show();
    loadAndCheckDatabase();
    splash.Close();
}

问题在于,阴 sp检查只得到部分抽取,因此,它确实像许多闪电屏幕一样。 任何想法为什么? 我应该做些什么?

就奖金点而言,任何人都知道,在典型创造、使用和销毁形式方面,如何解释所有一系列事件? 以上问题很可能是因为我不理解发生什么命令,或忽略什么情况。


UPDATE Close, but not quite: looking for a little more advice. Here s the current code:

private SplashScreen splash = new SplashScreen();

private void RealForm_Load(object sender, EventArgs e)
{

    splash.Show();

    BackgroundWorker worker = new BackgroundWorker();
    worker.DoWork += new DoWorkEventHandler(worker_DoWork);
    worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler
         (worker_RunWorkerCompleted);
    worker.RunWorkerAsync();
    this.Visible = false;

}

void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
    splash.Close();
    this.Visible = true;
}

void worker_DoWork(object sender, DoWorkEventArgs e)
{
    loadAndCheckDatabase();
}

不幸的是,<代码>。 可见度=虚假 做不到任何事情,因为它自动被定在我不控制的法典中true。 因此,为了做到这一点,我提出了<代码>。 Visible = 伪造的 进入手稿Shown活动。 然而,正如你可能猜测的那样,你仍然能够看到分裂的第二种形式......这样实际上不是一个好的解决办法。

在我仍留在洛德手勒时,是否有办法等待工人的read子?

最佳回答

你们正在展示大刀切的屏幕,并检查你的数据库。 read只能够做一件事。

解决这一问题的快捷、廉价方式是定期使用<代码> AndCheckDatabase(>。 然而,这种固定办法便宜。

您真的希望自己在座标上操作AndCheckDatabase() 。 这是这样做的简单方法。

问题回答

和我一样,这很可能是作为事后思考创造的,并不希望通过重新设计你的法典以适应多面建筑的所有轮ck。

第一,在被点击背景Image和进口你想要的图像的财产中,建立一个称为SapshScreen的新表格。 还把表格B排序为零,以便你能够点击X以关闭屏幕。

    public Form1()
    {
        InitializeComponent();

        BackgroundWorker bw = new BackgroundWorker();
        bw.WorkerSupportsCancellation = true;
        bw.DoWork += new DoWorkEventHandler(bw_DoWork);
        bw.RunWorkerAsync();  // start up your spashscreen thread
        startMainForm();      // do all your time consuming stuff here  
        bw.CancelAsync();     // close your splashscreen thread  
    }


    private void bw_DoWork(object sender, DoWorkEventArgs e)
    {
        BackgroundWorker worker = sender as BackgroundWorker;

        SplashScreen ss = new SplashScreen();
        ss.Show();

        while (!worker.CancellationPending) //just hangout and wait
        {
            Thread.Sleep(1000);
        }

        if (worker.CancellationPending)
        {
            ss.Close();
            e.Cancel = true;
        }

    }

这不支持进展障碍或任何缺陷,但我确信,进展可能受到 t弄。

要求装货 AndCheckDatabase, in a background read, trans the end of the lash Screen where, or一刀切地将其关闭。 随着工作背景的临近,所有金融情报中心的职能都将能够不间断地运作。

你们应该以不同的眼光进行间隙检查,以便适当抽取。

look:

http://www.codeproject.com/KB/cs/prettygoodsplashcr.aspx

为什么在你执政时,你不能够打上你需要装上哪类的表格,而是在装货时,打开你的主要形式,把这几类武器送进去? 或者,你可以使用单一吨来装载一切。

贵方案:

    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new SplashScreen());
    }

随后在SplashScreen:

    public SplashScreen()
    {
        InitializeComponent();
        LoadEverything();
        this.Visible = false;
        MainForm mainForm = new MainForm(LoadedClass);
        mainForm.ShowDialog();
        this.Close();
    }

www.un.org/Depts/DGACM/index_spanish.htm 我需要更新:。

这里的《工作法典》(以上只是概念)。

    public SplashScreen()
    {
        InitializeComponent();
        _currentDispatcher = Dispatcher.CurrentDispatcher;

        // This is just for the example - start a background method here to call
        // the LoadMainForm rather than the timer elapsed
        System.Timers.Timer loadTimer = new System.Timers.Timer(2000);
        loadTimer.Elapsed += LoadTimerElapsed;
        loadTimer.Start();
    }

    public void LoadMainForm()
    {
        // Do your loading here
        MainForm mainForm = new MainForm();

        Visible = false;
        mainForm.ShowDialog();
        System.Timers.Timer closeTimer = new System.Timers.Timer(200);
        closeTimer.Elapsed += CloseTimerElapsed;

        closeTimer.Start();
    }

    private Dispatcher _currentDispatcher;

    private void CloseTimerElapsed(object sender, System.Timers.ElapsedEventArgs e)
    {
        if (sender is System.Timers.Timer && sender != null)
        {
            (sender as System.Timers.Timer).Stop();
            (sender as System.Timers.Timer).Dispose();
        }
        _currentDispatcher.BeginInvoke(new Action(() => Close()));
    }

    private void LoadTimerElapsed(object sender, System.Timers.ElapsedEventArgs e)
    {
        if (sender is System.Timers.Timer && sender != null)
        {
            (sender as System.Timers.Timer).Stop();
            (sender as System.Timers.Timer).Dispose();
        }
        _currentDispatcher.BeginInvoke(new Action(() => LoadMainForm()));
    }

You can use the await command with .Net Framework 4.5 Your form will not be visible until the task is completed

    private void YourForm_Load(object sender, EventArgs e)
    {
        //call SplashScreen form
        SplashScreen splash = new SplashScreen();
        splash.Show();
        Application.DoEvents();
        //Run your long task while splash screen is displayed i.e. loadAndCheckDatabase
        Task processLongTask = loadAndCheckDatabase();
        //wait for the task to be completed
        processLongTask.Wait();
        splash.Close();

        //...
    }




相关问题
Bring window to foreground after Mutex fails

I was wondering if someone can tell me what would be the best way to bring my application to the foreground if a mutex was not able to be created for a new instance. E.g.: Application X is running ...

How to start WinForm app minimized to tray?

I ve successfully created an app that minimizes to the tray using a NotifyIcon. When the form is manually closed it is successfully hidden from the desktop, taskbar, and alt-tab. The problem occurs ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

Handle DataTable.DataRow cell change event

I have a DataTable that has several DataColumns and DataRow. Now i would like to handle an event when cell of this DataRow is changed. How to do this in c#?

Apparent Memory Leak in DataGridView

How do you force a DataGridView to release its reference to a bound DataSet? We have a rather large dataset being displayed in a DataGridView and noticed that resources were not being freed after the ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

WPF-XAML window in Winforms Application

I have a Winforms application coded in VS C# 2008 and want to insert a WPF window into the window pane of Winforms application. Could you explain me how this is done.

热门标签