Play animated gif on waiting

L

Lemune

Hi..
I am developing an application that connect to database on the other
side of the net.
And each time i want to connect to database and run some sql command,
i want my user to know that there is some process is runing. My idea
is to show animated gif until the process is done.
My question is how i could achieved that? Any one could give me a clue
or hint or even sample code?
Thank you?
This is my snippet code:

Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdSave.Click
Dim strQuery As String
Dim Connection As New clsConnection 'I am using my class
Dim Settings As New clsSettings 'I am using my class
Dim blnConnect As Boolean = False
Private Const strAppName As String
If NotNull(txtName) Or NotNull(txtUnit) Or NotNull(txtPacking)
Or NotNull(txtPoint) Or NotNull(txtPricePoint) Or NotNull(txtPrice)
Then
MsgBox("Data with * mark must not empty.",
MsgBoxStyle.Information, "Information")
Exit Sub
End If
'Here i want o star play animated gif
If
Connection.OpenConnection(Settings.getStrConnection(strAppName)) =
True Then
Clear()
blnConnect = True
Else
'stop animated gif
MsgBox("Could not connect to database.",
MsgBoxStyle.Critical, "Warning.")
blnConnect = False
Exit Sub
End If
strQuery = "Insert Into products
(name,unit,packaging,point,price_point,price) VALUES ('" &
txtName.Text & "','" & _
txtUnit.Text & "','" & txtPacking.Text & "','" &
txtPoint.Text & "','" & txtPricePoint.Text & "','" & _
txtPrice.Text & "')"

Select Case conProduct.Transaction(strQuery)
Case Is < 0
MsgBox("There is an error when saving data.",
MsgBoxStyle.Information, "Information")
Connection.TerminateDatabase()
'stop animated gif
Exit Sub
Case Is = 0
MsgBox("There is no data saved.",
MsgBoxStyle.Information, "Information")
Connection.TerminateDatabase()
'stop animated gif
Exit Sub
Case Else
MsgBox("Data has been saved.",
MsgBoxStyle.Information, "Information")
End Select
Connection.TerminateDatabase()
'stop animated gif
Clear()
End Sub
 
C

Cor Ligthert [MVP]

Alfred

Drag a picturebox on your form
Set it to dock fill
Set Sizemode to StretchImaga
Choose in your property box your gif annimation

That is all

Cor
 
A

Armin Zingler

Cor Ligthert said:
Alfred

Drag a picturebox on your form
Set it to dock fill
Set Sizemode to StretchImaga
Choose in your property box your gif annimation

That is all


Will it be animated in another thread? (I didn't try) Because the same
thread will be blocked.


Armin
 
L

Lemune

I have tried your suggestion Cor.
And I'm using Property Visible
But for my application it doesn't work.
So i tried make a simple one that use command button and it's work
well.
This is my simple application:
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles OK.Click
if pbAnimation.Visible=True Then
pbAnimation.Visible=False
else
pbAnimation.Visible=True
end if
End Sub

But for real application (my question), it not work, it didn't showing
the animation.
 
C

Cor Ligthert [MVP]

Lemune,

At least you have to put it on a seperate form.
I thougth that was working because the gif has its own annimation however I
am not sure of that.

Cor
 
L

Lemune

Thanks Cor, for your answer.
But it still not working.
I create a simple form that only had pbAnimation.
Then in my application(the question), first i create the instance of
the form, then show it.
Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdSave.Click
Dim frmPending As New Pending
frmPending.Show()
'
'
'
On each time i want to stop the animation, I hide the form. But It's
doesn't work like i wanted.
It still didn't show the animated gif, the time to load is about 3 s.
 
A

Armin Zingler

Lemune said:
Thanks Cor, for your answer.
But it still not working.
I create a simple form that only had pbAnimation.
Then in my application(the question), first i create the instance of
the form, then show it.
Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdSave.Click
Dim frmPending As New Pending
frmPending.Show()
'
'
'
On each time i want to stop the animation, I hide the form. But It's
doesn't work like i wanted.
It still didn't show the animated gif, the time to load is about 3
s.


As I guessed, the animation does not show because there is no time to
animate the gif because the thread is busy opening the connection. So you
have (at least) two options: Create a Form containing the Gif, as Cor said,
but in another thread. The thread won't be blocked and can animate the Gif.
Or, keep the gif on the same Form and open the connection in another thread.
This will take some more efforts because the application will have to handle
a "opening connection" state and your sub will have to be split into two
parts: one before and one after opening the connection. If it's worth just
for an animated Gif, I would probably put the whole saving task into a
seperate thread, not only opening the connection (unless you need it
multiple times; as always it depends...). Otherwise just show the
"WaitCursor" Cursor.


Armin
 
L

Lemune

Thanks Cor and Armin.
I will use wait cursor instead.
My purpose is to make user know that something is in process, and with
wait cursor i think is enough, because microsoft also used it.
So my user will be knew about it
Once again thanks for both of you.

Lemune,
Always learn.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top