Need help - How to display loading image in Winform ?
Hi,
We have 1 WinForm application developed using VB.NET (.NET Framework 3.0). In this application we have used 1 tree view control and a group box. The group box contains the ComponentOne's TrueDBGrid.
When we click on/select the node from tree view we are fetching the data from database and displaying it on the grid. This process is taking the time to display data. So we want that some animated loading image should be displayed to indicate that process is going on. For this we have placed 1 picture box control (containing animated loading image just like we use with Ajax) in the group box. After click on a tree view node we are hiding grid and displaying picture box and after assigning a data source to the grid we are hiding picture box and displaying gird. Below is our code.
In the below code if we add "Application.DoEvents()" after showing picture box then the image of picture box is appearing on the WinForm while running the application otherwise not. Now after adding "Application.DoEvents()" the picture box is appearing but the image is looking plane and not animated.
So does anyone knows that why the image is appearing plane and what we will have to do to display animated image? We want to keep application and code simple so we have not used threading, progress bar and background worker process controls etc.
Private Sub tvDatabaseObjects_NodeMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeNodeMouseClickEventArgs) Handles tvDatabaseObjects.NodeMouseClick
Try
''''' Hide grid
tdbgLookup.Visible = False
''''' Display picture box
pbLoading.Visible = True
pbLoading.Width = 219
pbLoading.Height = 20
pbLoading.Location = New Point(297, 216)
pbLoading.Show()
Me.Cursor = Cursors.WaitCursor
''''' If we add below line of code then form will show picture box otherwise not
''''' Application.DoEvents()
If e.Node.Nodes.Count = 0 Then
'''' Code will go here to load data into datagrid
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''' Hide picture box
pbLoading.Visible = False
'''' Display grid
tdbgLookup.Visible = True
tdbgLookup.Show()
Me.Cursor = Cursors.Default
Else
End If
Catch ex As Exception
Exit Sub
End Try
End Sub
Thanks and Regards
Prasad