You should use Invoke to open the splash form on the main UI thread.
http://msdn.microsoft.com/en-us/library/zyzhdc6b.aspx

Nathan

From: ausdotnet-boun...@lists.codify.com 
[mailto:ausdotnet-boun...@lists.codify.com] On Behalf Of Anthony
Sent: Friday, 26 February 2010 12:50 PM
To: 'ausDotNet'
Subject: Splash Screen..thread safe

I have created a class to so i can show a splah screen when ever i need to 
notify information to the user...works fine but  having issues when i run it 
within a thread...how would i make it tread safe?

I have  instantiated it within the main form...


Imports System.Windows.Forms

Public Class FormSplash

    Dim oControl As Control()
    Dim oSplash As System.Windows.Forms.Form

    Sub New()
        oSplash = CreateSplash("", "")
    End Sub

    Public Sub ShowText(ByVal ParentForm As Form, ByVal sText As String)
        oSplash.StartPosition = FormStartPosition.Manual
        oSplash.Location = New System.Drawing.Point(ParentForm.Location.X + 
((ParentForm.Bounds.Width - oSplash.Width) \ 2), ParentForm.Location.Y + 
((ParentForm.Bounds.Height - oSplash.Height) \ 2))
        oControl = oSplash.Controls.Find("label1", True)
        oControl(0).Text = sText
        Application.DoEvents()
        oSplash.Show()
        Application.DoEvents()
    End Sub

    Public Sub Hide()
        oSplash.Hide()
    End Sub


    Public Function CreateSplash(ByVal Header As String, ByVal sText As String) 
As Form

        Dim Splash As New Form
        Dim label1 As New Label

        label1 = New System.Windows.Forms.Label()
        Splash.SuspendLayout()
        '
        ' label1
        '
        label1.AutoSize = True
        label1.Location = New System.Drawing.Point(13, 46)
        label1.Name = "label1"
        label1.Size = New System.Drawing.Size(35, 13)
        label1.TabIndex = 0
        label1.Text = sText
        '
        ' Splash
        '
        Splash.AutoScaleDimensions = New System.Drawing.SizeF(6.0F, 13.0F)
        Splash.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Splash.ClientSize = New System.Drawing.Size(454, 97)
        Splash.ControlBox = False
        Splash.Controls.Add(label1)
        Splash.MaximizeBox = False
        Splash.MinimizeBox = False
        Splash.Name = "Splash"
        Splash.Opacity = 1
        Splash.ShowIcon = False
        Splash.ShowInTaskbar = False

        Splash.Text = Header
        Splash.TopMost = True
        Splash.ResumeLayout(False)
        Splash.PerformLayout()

        Return Splash
    End Function


End Class

Is your website being 
IntelliXperienced?<http://www.intellixperience.com/signup.aspx>
regards
Anthony (*12QWERNB*)
Is your website being IntelliXperienced?


Reply via email to