Click to See Complete Forum and Search --> : How to keep buttons available at all times!


Dozo_1st
March 30th, 2004, 06:49 AM
Well, got another problem for the developers here, which I cannot solve :blush: :

How does one keep a Cancel-button available at all times on a form?

While copying I use a label displaying what is copied at the moment and keep refreshing the form. If I do not refresh the form, all I see on screen is an outline of the form and everything in it is "transparent".

The problem this has, is that the Cancel-button is not available anymore. You can click all you want, but nothing happens :mad: :mad:

code is the following:
Private Sub lblStatus_TextChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles lblStatus.TextChanged
lblStatus.Refresh()
End Sub
For Each sFile
sFileInfo.CopyTo(dFileInfo.FullName, overWrite)
lblStatus.Text = "Busy copying" & vbCrLf & sFileInfo.FullName & _
vbCrLf & " to " & vbCrLf & dFileInfo.FullName
Next

Craig Gemmill
March 30th, 2004, 10:13 AM
I'm sure there are other ways to do it, but these are the three I have always used:

Delete the code in TextChanged:

Private Sub lblStatus_TextChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles lblStatus.TextChanged
lblStatus.Refresh()
End Sub


1) Change your function to use DoEvents:

For Each sFile
sFileInfo.CopyTo(dFileInfo.FullName, overWrite)
lblStatus.Text = "Busy copying" & vbCrLf & sFileInfo.FullName & _
vbCrLf & " to " & vbCrLf & dFileInfo.FullName

'
'Allow UI to catch up
'
Application.DoEvents

Next


2) Create a second thread to do the processing. However, when you are updating UI, this is not a good option.

3) Create another Form/UserControl (Thread w/UI) that does the processing and has it's own label for displaying progress.

Gizmo001
March 30th, 2004, 10:58 AM
I don't see why the cancel button should disappear. In your code you are refreshing "lblStatus." Try to refresh the form using Me.refresh and may be add "cancelbutton.visible=true" after that.