|
-
Jan 11th, 2012, 07:35 AM
#1
Thread Starter
Frenzied Member
-
Jan 11th, 2012, 08:53 AM
#2
Hyperactive Member
Re: Splash Screen Best Way
like this:
in the splash form
Code:
Delegate Sub SetTextCallback(ByVal msg As String)
Public Sub UpdateWorkLabel(ByVal msg As String)
If lblWork.InvokeRequired Then
' It's on a different thread, so use Invoke.
Dim d As New SetTextCallback(AddressOf UpdateWorkLabel)
Invoke(d, New Object() {msg})
Else
if msg = "HIDEME" Then
Hide()
Close()
Else
' It's on the same thread, no need for Invoke.
lblWork.Text = msg
End If
End If
Application.DoEvents()
End Sub
in main form
Code:
Dim fs As New frmSplash
Dim t As New Thread(AddressOf fs.ShowDialog)
t.IsBackground = True
t.Priority = ThreadPriority.AboveNormal
t.Name = "Splash form"
t.Start()
and then any time in mainform_load you can do something like this:
Code:
fs.UpdateWorkLabel("Processing foo")
<do some work>
fs.UpdateWorkLabel("Processing bar")
<do some work>
when you are all done loading and want to hide the splash screen, do this:
Code:
fs.UpdateWorkLabel("HIDEME")
extending that to add a boolean flag is easy enough: just declare it and check it whenever you need to in your main form and act appropriately
Last edited by EricPeterson87; Jan 11th, 2012 at 08:54 AM.
Reason: code cleanup
-
Jan 11th, 2012, 10:24 AM
#3
Thread Starter
Frenzied Member
Re: Splash Screen Best Way
Thanks
I almost solved the problem with similar approach the only thing that i didn't use was the delegate, the final code that i'm using:
Splash Form:
vb.net Code:
Public Class MySplash Public Event KeyPressed() Delegate Sub SetTextCallBack(ByVal message As String) Public Sub UpdateMessage(ByVal message As String) If LabelMessage.InvokeRequired Then 'Different thread Dim d As New SetTextCallBack(AddressOf UpdateMessage) Invoke(d, New Object() {message}) Else LabelMessage.Text = message End If End Sub Private Sub Form2_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown If e.Shift Then RaiseEvent KeyPressed() End Sub End Class
MainForm Code:
vb.net Code:
Public Class MainForm Private splash As MySplash Private threadSP As Threading.Thread Private Sub ShowLoginForm() If LoginForm.ShowDialog <> Windows.Forms.DialogResult.OK Then MsgBox("Login Failed", MsgBoxStyle.Information) End End If threadSP.Abort() End Sub Public Sub New() splash = New MySplash splash.TopMost = True threadSP = New Threading.Thread(New Threading.ThreadStart(AddressOf splash.ShowDialog)) AddHandler splash.KeyPressed, AddressOf ShowLoginForm threadSp.Start() 'Task1 splash.UpdateMessage("Task1........") Threading.Thread.Sleep(2000) 'Task2 splash.UpdateMessage("Task2........") Threading.Thread.Sleep(2000) 'Task3 splash.UpdateMessage("Task3........") Threading.Thread.Sleep(2000) ' This call is required by the designer. InitializeComponent() ' Add any initialization after the InitializeComponent() call. threadSp.Abort() End Sub End Class
Last edited by mickey_pt; Jan 11th, 2012 at 10:34 AM.
Reason: Public > Private
Rate People That Helped You
Mark Thread Resolved When Resolved
-
Jan 11th, 2012, 10:47 AM
#4
Hyperactive Member
Re: [RESOLVED] Splash Screen Best Way
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|