如何使用启动画面正确加载表单? [英] how to load form properly using Splash Screen?

查看:73
本文介绍了如何使用启动画面正确加载表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我加载启动画面时,我的表单不加载计算机端口"来发送消息吗?
如果我不使用它的启动画面,该怎么办?.

我想说的是,当我使用Splash Screen加载应用程序而没有问题时,它的工作非常完美(Form1).但是当我使用Splash Screen(Form2)使用该Form时,它无法完美运行.(意味着Form1无法完美加载

这个类来打开或关闭端口

When i load tha splash screen my form does not load "ports of computer" to send msgs?
if i dont use tha splash screen its work properly what should i do..??

i am trying to say that when i load application with out using Splash Screen its work perfectly(Form1). But when i use that Form using Splash Screen(Form2) its not work perfectly.(means Form1 does not load perfectly

this the class to open or close ports

namespace SMS
{
    class SmsClass
    {
        SerialPort serialPort;
        public SmsClass(string comPort)
        {
            this.serialPort = new SerialPort();
            this.serialPort.PortName = comPort;
            this.serialPort.BaudRate = 9600;
            this.serialPort.Parity = Parity.None;
            this.serialPort.DataBits = 8;
            this.serialPort.StopBits = StopBits.One;
            this.serialPort.Handshake = Handshake.RequestToSend;
            this.serialPort.DtrEnable = true;
            this.serialPort.RtsEnable = true;
           
        }
        public bool sendSms(string cellNo, string sms)
        {
            string messages = null;
            messages = sms;
            if (this.serialPort.IsOpen == true)
            {
                try
                {
                    this.serialPort.NewLine = System.Environment.NewLine;
                    this.serialPort.WriteLine("AT" + (char)(13));
                    Thread.Sleep(4);
                    this.serialPort.WriteLine("AT+CMGF=1" + (char)(13));
                    Thread.Sleep(5);
                    this.serialPort.WriteLine("AT+CMGS=\"" + cellNo + "\"");
                    Thread.Sleep(10);
                    this.serialPort.WriteLine(">" + messages + (char)(26));
                }
                catch (Exception ex)
                {
                    //MessageBox.Show(ex.Source);
                }
                return true;
            }
            else
                return false;
        }

        public void Opens()
        {
            if (this.serialPort.IsOpen == false)
            {
                this.serialPort.Open();
            }
        }
        public void Closes()
        {
            if (this.serialPort.IsOpen == true)
            {
                this.serialPort.Close();
            }
        }
    }
}



但是当我尝试使用第一种形式打开第二种形式时,此端口不会加载



but when i try to open a 2nd form using 1st form this ports does not load

推荐答案

谢谢!

这个问题很容易看清(可能很难解决)
Thank you!

The problem is pretty simple to see (it may be harder to work out a fix)
timer1.Stop(); // Before calling f2.ShowDialog(), stops the timer event
Hide();
f3.ShowDialog();
Close();

ShowDialog是一个模式调用或阻塞调用-在关闭调用它的窗体之前,它不会返回.因此,在Form2实例(启动屏幕)完成其工作并关闭之前,Form2类中不会再发生任何事件.这样就不会显示进度,也不会显示消息,也根本不会更新UI.

取而代之的是,为Form3.Closed事件添加一个处理程序,并使用该处理程序关闭Form2.只需使用f3.Show()而不是f3.ShowDialog()并在其后删除Close-如果在显示form3之后关闭form2,则由于它被声明为form2类级别引用,它也会破坏form3实例.

ShowDialog is a modal or blocking call - it does not return until the form it is called on is closed. So no further events happen in your Form2 class until the instance of Form3 (the splash screen) has done it''s job, and closed. So not progress display, not messages, no UI updates at all.

Instead of that, add a handler for the Form3.Closed event, and use that to Close Form2. Just use f3.Show() instead of f3.ShowDialog() and remove the Close after it - if you close form2 after displaying form3, it will also destroy the form3 instance, since it is declared as a form2 class level reference.


这篇关于如何使用启动画面正确加载表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆