|
-
Oct 23rd, 2008, 08:19 AM
#1
Thread Starter
New Member
[2005] Open and closing forms
Ok here is what I am trying to do. I have a form that has an option to view event logs, when that button is clicked this is what i want it to do
pop up a window that just has a progressbar that will run as a loading bar,
but the other window that will display the logs i want to be opened at the same time, but not visible bc it sometiems takes time to load all the logs, then after a certain time the progressbar window will close and the viewlog window will become visible. for whatever reason i got lost on what to do.
-
Oct 23rd, 2008, 09:14 AM
#2
Re: [2005] Open and closing forms
So for form2, you want to create it and load all the controls before calling either Show or ShowDialog. Since you wouldn't want the app to hang while you are loading the form, you probably want to do the loading in a background thread. Here's some code from a form where I did that:
Code:
Private Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
mNotNow = True
End Sub
Public Shared Sub Initialize()
PICTransect = New PICTransectCustom
End Sub
Public Sub SetUp(ByVal cnStr As String)
Me.lMess1.Text = "Loading..."
Me.lMess2.Text = "...Please Wait"
mConnectionString = cnStr
uiContext = System.Threading.SynchronizationContext.Current
mMut1 = New System.Threading.Mutex
mImValid = False
mData = New DataSet
mFillT1 = New Threading.Thread(AddressOf FillData)
mFillT1.IsBackground = True
mFillT1.Start()
End Sub
Private Sub FillData()
Dim cn As New System.Data.OleDb.OleDbConnection(mConnectionString)
Dim da As New System.Data.OleDb.OleDbDataAdapter
Dim cmd As System.Data.OleDb.OleDbCommand = Nothing
Try
Try
cn.Open()
Catch ex As Exception
mError = "Failed to Open"
Return
End Try
'Just filled three tables in here, but removed the code for this example
mImValid = True
BindDataToCombo()
uiContext.Post(AddressOf EventRaiser, Nothing)
End Sub
Private Sub BindDataToCombo()
If dgvStreams.InvokeRequired Then
Me.dgvStreams.Invoke(New MethodInvoker(AddressOf BindDataToCombo))
Else
If mImValid Then
mNotNow = True
Me.lbNamedTransect.DisplayMember = "Transect"
Me.lbNamedTransect.ValueMember = "ID"
Me.lbNamedTransect.DataSource = mdvTransect
Me.dgvStreams.DataSource = mdvGrid
Me.dgvStreams.Columns("HydroID").Visible = False
Me.lbRouteStart.DisplayMember = "RouteName"
Me.lbRouteStart.ValueMember = "HydroID"
Me.lbRouteStart.DataSource = mdvRouteStart
Me.lbRouteEnd.DisplayMember = "RouteName"
Me.lbRouteEnd.ValueMember = "HydroID"
Me.lbRouteEnd.DataSource = mdvRouteEnd
Me.cbStreams.DisplayMember = "HName"
Me.cbStreams.DataSource = mData.Tables("StreamTable")
mNotNow = False
Else
Windows.Forms.MessageBox.Show(mError)
End If
End If
End Sub
Private Event LoadDone()
Private Sub EventRaiser(ByVal state As Object)
RaiseEvent LoadDone()
End Sub
Note that the synchronization context is stored prior to starting the background thread. By doing this, I can raise the LoadDone event on the synchronization context of the UI thread, thereby raising the event in the UI thread.
Also, if you are wondering about the Shared Initialize, the reason for that is because the form in question is a Singleton construct.
My usual boring signature: Nothing
 
-
Oct 23rd, 2008, 01:14 PM
#3
Thread Starter
New Member
Re: [2005] Open and closing forms
Ok thanks, im going to have to look at that and try to understand it haha
-
Oct 23rd, 2008, 01:29 PM
#4
Re: [2005] Open and closing forms
I can explain any piece you are wondering about.
My usual boring signature: Nothing
 
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
|