Click here to Skip to main content
15,891,704 members
Please Sign up or sign in to vote.
1.67/5 (2 votes)
See more:
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
C#
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
Posted
Updated 21-Nov-12 3:08am
v2
Comments
OriginalGriff 21-Nov-12 8:27am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Use the "Improve question" widget to edit your question and provide better information.
Herman<T>.Instance 21-Nov-12 9:09am    
This part of source does not indicate any call to Form2/splashform neither a Close() command to it.
Member 9411249 21-Nov-12 9:15am    
this is the Form2 opening a form3

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsAppDAL
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
Form3 f3 = new Form3();

private void timer1_Tick(object sender, EventArgs e)
{

if (progressBar2.Value < 100)
{
progressBar2.Value += 2;
}
else
{
timer1.Stop(); // Before calling f2.ShowDialog(), stops the timer event
Hide();
f3.ShowDialog();
Close();
}
//progressBar1.Increment(1);

}
}
}


this is the form3 opening a Form2

using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsAppDAL
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}

private void applicationToolStripMenuItem_Click(object sender, EventArgs e)
{
Form1 fm2 = new Form1();

fm2.Show();
}
}
}

my Application is in form2
Nelek 21-Nov-12 17:37pm    
Next time please use the widget "improve question" and add the code snippet to your message. It is easy to read there between code block than here as comment
OriginalGriff 21-Nov-12 9:15am    
Please, bear in mind that we only get to work with what you tell us - since you haven't told us how you show your splash screen, or where and how you use your SmsClass, we can't tell what the problem is.
You need to add the relevant code fragments, or we have to guess, and that doesn't work too well! :laugh:

1 solution

Thank you!

The problem is pretty simple to see (it may be harder to work out a fix)
C#
timer1.Stop(); // Before calling f2.ShowDialog(), stops the timer event
Hide();
f3.ShowDialog();
Close();
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.
 
Share this answer
 
Comments
Member 9411249 21-Nov-12 9:30am    
Thank you :)its work for me...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900