By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,699 Members | 1,243 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,699 IT Pros & Developers. It's quick & easy.

Form load?

P: n/a
Dear friends

In my app the main form is processing a lot of code. Thats why it takes a
pretty long time to paint the form. Because of that i want to first paint
another form displaying some sort of wait message waile the main form is
processing invisible in the background. At the second the main form is
finished loading I want the waiting form to close and the main form to
paint.

Somebody guide me to the right approach to achieve this goal?

Regards Able
Nov 21 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Dear Able

Look at Armin Zinglers great multi threaded example:

http://people.freenet.de/armin.zingl...adedSplash.zip
"able" <ab**@epost.no> skrev i melding
news:UA********************@news4.e.nsc.no...
Dear friends

In my app the main form is processing a lot of code. Thats why it takes a
pretty long time to paint the form. Because of that i want to first paint
another form displaying some sort of wait message waile the main form is
processing invisible in the background. At the second the main form is
finished loading I want the waiting form to close and the main form to
paint.

Somebody guide me to the right approach to achieve this goal?

Regards Able

Nov 21 '05 #2

P: n/a
Able,

I have here a new sample without the multithreading, in my opinion it does
the same as the one you have, have a look for it. I made it from some
arguing with Larry and Jay this week, so when they see it, let those or
others feel free to give comments.

\\\form1 needs 2 textboxes and a button
Private WithEvents frm As Form2
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim timer1 As New System.Windows.Forms.Timer
AddHandler timer1.Tick, AddressOf mytimer1
TextBox1.Text = "0"
timer1.Enabled = True
timer1.Interval = 400
Dim timer2 As New System.Windows.Forms.Timer
End Sub
Public Sub mytimer1(ByVal sender As Object, _
ByVal e As System.EventArgs)
TextBox1.Text = (CInt(TextBox1.Text) + 1).ToString
DirectCast(sender, System.Windows.Forms.Timer).Enabled = True
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
frm = New Form2
frm.Show()
frm.Top = Me.Top
frm.Left = Me.Left + 200
End Sub
Private Sub f_form2ready(ByVal message As String) _
Handles frm.form2ready
TextBox2.Text = message
frm.Dispose()
End Sub
///
\\\form2 needs one textbox
Friend Event form2ready(ByVal message As String)
Private Sub Form2_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim timer1 As New System.Windows.Forms.Timer
AddHandler timer1.Tick, AddressOf mytimer1
timer1.Enabled = True
timer1.Interval = 300
End Sub
Public Sub mytimer1(ByVal sender As Object, _
ByVal e As System.EventArgs)
Static counter As Integer = 0
Dim mystring As String = "I am searching for the time "
TextBox1.Text = mystring.Substring(counter)
DirectCast(sender, System.Windows.Forms.Timer).Enabled = True
counter += 1
If counter = 22 Then
DirectCast(sender, Timer).Enabled = False
RaiseEvent form2ready(Now.TimeOfDay.ToString)
Else
Me.Opacity -= 0.04
DirectCast(sender, Timer).Enabled = True
End If
End Sub
///
Nov 21 '05 #3

P: n/a
Hi

I was not statisfied with the sample, so I made a new one beneath, this is a
sample that has 2 splash forms, one by multithreading and one withouth
multithreading.

Just again mostly meant for arguing

:-)

Cor

\\\needs on form 1 one button and three textboxes
Private WithEvents frm1 As Form2
Public Delegate Sub Frm1Handler(ByVal message As String)
Private WithEvents frm2 As Form2
Dim MyThread As System.Threading.Thread
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim timer1 As New System.Windows.Forms.Timer
AddHandler timer1.Tick, AddressOf mytimer1
TextBox1.Text = "0"
timer1.Enabled = True
timer1.Interval = 400
Dim timer2 As New System.Windows.Forms.Timer
End Sub
Public Sub mytimer1(ByVal sender As Object, _
ByVal e As System.EventArgs)
TextBox1.Text = (CInt(TextBox1.Text) + 1).ToString
DirectCast(sender, System.Windows.Forms.Timer).Enabled = True
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
frm1 = New Form2
frm1.itstop = Me.Top
frm1.itsleft = Me.Left + 200
frm1.Text = "Extra thread"
MyThread = New System.Threading.Thread(AddressOf frm1.Show)
MyThread.Start()
frm2 = New Form2
frm2.itstop = Me.Top
frm2.itsleft = Me.Left + 400
frm2.Text = "In own thread"
frm2.Show()
End Sub
Protected Sub Frm1Ready(ByVal message As String)
Me.BeginInvoke(New Frm1Handler(AddressOf Frm1HandlerSub), New
Object() {message})
End Sub
Public Sub Frm1HandlerSub(ByVal message As String)
TextBox2.Text = message
frm1.Close()
MyThread.Abort()
End Sub
Private Sub frm2ready(ByVal message As String) _
Handles frm2.form2ready
TextBox3.Text = message
frm2.Dispose()
End Sub
///
\\\Needs a form2 with one textbox
Friend Event form2ready(ByVal message As String)
Friend itstop As Integer
Friend itsleft As Integer
Private Sub Form2_Activated(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Activated
Me.Left = itsleft
Me.Top = itstop
Me.BringToFront()
Dim timenext As DateTime = Now.Add(TimeSpan.FromSeconds(10))
Do While timenext > Now
TextBox1.Text = Now.TimeOfDay.ToString
Application.DoEvents() 'to show the time
Threading.Thread.Sleep(50)
Me.Opacity -= 0.004
Loop
RaiseEvent form2ready(Now.TimeOfDay.ToString)
End Sub
Private Sub Form2_Closing(ByVal sender As Object, ByVal _
e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
e.Cancel = True
End Sub
///
Nov 21 '05 #4

P: n/a

"Cor Ligthert" <no************@planet.nl> wrote

I made it from some arguing with Larry and Jay this week,


Hey Cor, I am sorry to hear you thought we were arguing,
I thought we were having a discussion!

Discussion = conversation
Arguement = angry conversation

;-)
LFS
Nov 21 '05 #5

P: n/a
Larry,

Me is told by an Englishman from London, a while very active in this
newsgroup.

Argumenting is having arguments (angry conversation)
Discussion is talking about someting however hs not toe be not arguable.
Arguing is what for me is from argue and is not argumenting.

However when I have understand it wrong again, I change it again.

We certainly do not have arguments.

:-)

Cor
"Larry Serflaten"

"Cor Ligthert" <no************@planet.nl> wrote

I made it from some arguing with Larry and Jay this week,


Hey Cor, I am sorry to hear you thought we were arguing,
I thought we were having a discussion!

Discussion = conversation
Arguement = angry conversation

;-)
LFS

Nov 21 '05 #6

P: n/a
Larry,

I saw some mistakes in my sample when I looked at your message what was
special for the discussion/argueing between us, about where we last talked
about and than I left them in my sample in some places myself.

So I show you a new version.

\\\needs on form 1 one button and three textboxes
Private WithEvents frm1 As Form2
Private Delegate Sub Frm1Handler(ByVal message As String)
Private WithEvents frm2 As Form2
Private MyThread As System.Threading.Thread
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim timer1 As New System.Windows.Forms.Timer
AddHandler timer1.Tick, AddressOf mytimer1
TextBox1.Text = "0"
timer1.Enabled = True
timer1.Interval = 400
Dim timer2 As New System.Windows.Forms.Timer
End Sub
Private Sub mytimer1(ByVal sender As Object, _
ByVal e As System.EventArgs)
TextBox1.Text = (CInt(TextBox1.Text) + 1).ToString
DirectCast(sender, System.Windows.Forms.Timer).Enabled = True
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
frm1 = New Form2
frm1.itstop = Me.Top
frm1.itsleft = Me.Left + 200
frm1.Text = "Extra thread"
MyThread = New System.Threading.Thread(AddressOf frm1.Show)
MyThread.Start()
frm2 = New Form2
frm2.itstop = Me.Top
frm2.itsleft = Me.Left + 400
frm2.Text = "In own thread"
frm2.Show()
End Sub
Private Sub Frm1Ready(ByVal message As String)
Me.BeginInvoke(New Frm1Handler(AddressOf Frm1HandlerSub), New
Object() {message})
End Sub
Private Sub Frm1HandlerSub(ByVal message As String)
TextBox2.Text = message
frm1.Close()
MyThread.Abort()
End Sub
Private Sub frm2ready(ByVal message As String) _
Handles frm2.form2ready
TextBox3.Text = message
frm2.Dispose()
End Sub
///
\\\Needs a form2 with one textbox
Friend Event form2ready(ByVal message As String)
Friend itstop As Integer
Friend itsleft As Integer
Private Sub Form2_Activated(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Activated
Me.Left = itsleft
Me.Top = itstop
Me.BringToFront()
Dim timenext As DateTime = Now.Add(TimeSpan.FromSeconds(10))
Do While timenext > Now
TextBox1.Text = Now.TimeOfDay.ToString
Application.DoEvents() 'to show the time
Threading.Thread.Sleep(50)
Me.Opacity -= 0.004
Loop
RaiseEvent form2ready(Now.TimeOfDay.ToString)
End Sub
Private Sub Form2_Closing(ByVal sender As Object, ByVal _
e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
e.Cancel = True
End Sub
///
Nov 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.