Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

VB.NET Please Wait window from form

Posted on 2012-08-11
16
Medium Priority
?
3,180 Views
Last Modified: 2012-08-26
I have a form that exports a loaded datagridview  to excel.  When exporting, I would like the user to see a 'please wait' panel / form with a progress bar.

Can anyone advise the best way to do this?

The solution should be dynamic in that the export process can work from more than one datagridview.
0
Comment
Question by:mondintator
  • 6
  • 3
  • 2
  • +3
14 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 38284654
I see a tag for the BackgroundWorker.  Is that the direction that you are hoping to take?  Have you tried anything yet?  How can I help?
0
 

Author Comment

by:mondintator
ID: 38284710
I have it currently working by opening a new form via a separate thread, and I cancel the thread when done.  But it's not ideal as it's opening a new form.  I like the idea of the background worker because it doesn't cause rendering issues to the form when the other thread is running, and can look like it's embedded in the form.  But I can't get it to work as per the other thread.  So I thought I'd ask the best / recommended way to approach this.  My code for the backgroundworker is on the other query.
0
 
LVL 40
ID: 38284801
Instead of using another form, you could use a StatusStrip control at the bottom of the form. The StatusStrip provided with the framework offers the option of displaying a progress bar.

Since it is on the same form, no need to define a way to control the progress bar in the waiting form from the original form.

And the green color used to show the progress is bold enough that the user's sight is automatically attracted to it, so even users who do not have the habit of looking at status bars will see it.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:mondintator
ID: 38284934
A status strip is good, but I'd like to disable all of the screen and show an animated gif with the progress bar, and the option of cancelling the process.  Are there any other options?
0
 
LVL 15

Expert Comment

by:rajeeshmca
ID: 38287518
0
 

Author Comment

by:mondintator
ID: 38314644
Splash screen is good, but the splash screen has it's own icon if I alt + tab between applications, rendering my main form unaccessable because it's doing work (on a different thread).  How can I get my main form to display whilst it's doing the work, with the splash screen embedded into the form where the gif image is not affected?
0
 
LVL 16

Expert Comment

by:hjgode
ID: 38317492
I dont understand your requirements in complete. Sorry

You have a form with a datagrid. You enable the user to export the grid data to excel. You want to show a Progress Window with animated GIF and a Cancel button but dont want to use a new form and the actual form should be disabled. Correct?

If you dont want a new form, why not just have another contents of the form with animated GIF and Cancel button? Just design two contents in one form and make the one visible you like.

One answer here suggested to create a splash screen and your concern was that there are now two buttons visible in taskbar. There are functions to hide the button from the taskbar. So you could go with a second form without a button in taskbar.

If you still need assistance I would prefer to see a sketch of what you want to achieve.
0
 
LVL 16

Expert Comment

by:HooKooDooKu
ID: 38318784
I don't have much experience specifically in VB.NET, but back in my VB6 days (which was single threaded) what I would do is have a form with a progress bar, an abort button, and a label control.  I gave the form the boolean property m_Abort.  I then had functions which pseudo code that looked like this (but with error checking and error handling):

Start( Max as integer)
    progressbar.max = Max
    progresbar.value = 0 
    label.caption = cstr(progresbar.value) & " of " & cstr(progressbar.max)
    m_Abort = False

SetPosition(Value as integer)
    progressbar.value = Value
    label.caption = cstr(progresbar.value) & " of " & cstr(progressbar.max)

Inc()
    progressbar.value = progressbar.value + 1
    label.caption = cstr(progresbar.value) & " of " & cstr(progressbar.max)  

AbortProcess as Boolean
    DoEvents '(allowed form to respond to click events on abort button
    return m_Abort

OnAbortClicked
    if( MessageBox("Are you sure?") = Yes )
        m_Abort = true

Open in new window


Then in my processing loop, I simply called
if( PleaseWaitForm.AbortProcess )
    exit process               

Open in new window


Again, this is pseuodcode... but the basic idea was that calling the AbortProcess function gave the PleaseWait form the ability to respond to click events or drag-and-drop events, if Abort was ever clicked, a conformation message popped up, and if the Abort Button was ever confirmed, AbortProcess would return TRUE until the form was restarted.
0
 

Author Comment

by:mondintator
ID: 38333255
The main issue I have with a separate form / splashscreen is that when the main form is performing it's task, if I alt+tab to display my form it doesn't display (because it's busy).  Instead I can display the splash screen only.  I would like a solution that allows me to display my main form whilst it is performing the work, but with the 'please wait' image 'on top'.  The solutions suggested thus far do not allow for this.
0
 
LVL 40
ID: 38333305
Put the "Please Wait" image in a control (Label, PictureBox, UserControl) that sits over the other ones on the form. Since that control is part of the form. When the form has finished initializing, simply set the control Visible property to False.
0
 

Author Comment

by:mondintator
ID: 38333306
Thanks James - I think that will do it - I will give it a try.  Do you have any example code?
0
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 1200 total points
ID: 38333376
Well, very simple.

Have the stuff you want to display in a Control over the others, say lblWait.

Open the form, lblWait display the waiting message.

Do what you need to do.

Then:  lblWait.Visible = False

As long as a control is invisible, it is just as if it did not exist.
0
 
LVL 16

Expert Comment

by:hjgode
ID: 38333576
Do not forget to disable the other controls. If you do not disable, the user is able to use TAB to cycle the focus thru them and SPACE or ENTER may execute unwanted.
The TAB will work alos for controls behind other controls.
0
 

Author Closing Comment

by:mondintator
ID: 38333957
All of James' advice proved useful.
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question