Link to home
Start Free TrialLog in
Avatar of drb2k2
drb2k2

asked on

Closing open file dialog before proceeding

Hi all,
I have a program that reads in large files. At the moment once a user selects the file to load the open file dialog box stays on the screen and the program looks like its crashed until the file has finally been read. I have set up a label to display the loading progress on the main form, but this is never seen because the open file dialog doesn't dissapear.

I guess what i'm asking is:
Is there a way to make sure that the open file dialog has closed, and that the main form has focus before moving onto the next function?

i've tried
        Dim file As String = Me.OpenFileDialog1.FileName
Me.OpenFileDialog1.Dispose()
        LoadFile(file)

to no avail.
I've also tried doing an infinite loop until the filename is nothing, or until the file dialog is nothing. Neither worked.

Any suggestions gratefully received.

Cheers
DRB2k2
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

It's not completely clear what you are doing.

I suspect that you are not using the Common File Dialog because that has no Dispose method. It just closes itself when you've got the file name.

However, the classic answer is to put some DoEvents in your code, especially in the reading loop, which I suppose that you must have in order to monitor the status.
Avatar of drb2k2
drb2k2

ASKER

ok, i'll try to be a bit clearer.

I am using a standard OpenFileDialog right off the toolbar, with absolutely no modifications from me what-so-ever (save for filtering the file extension).

Whats appears to be happening is that as soon as the open button is clicked the filename is passed onto the load function BEFORE the dialog has closed.

There seems to be no way to tell if the openfiledialog class has been closed so I can't halt the load function until the dialog has dissapeared.

The files I am loading in are 3D files that specify the number of vertices they have. What I'm doing to monitor the loading is every time one is read I change the text of a label to show this.

BUT, since the openfiledialog never closes, it still has focus and the background window is never redrawn.
So what happens if after a few seconds the dialog dissapears and presents the user with a label saying "100/100 vertices read". Which is completely useless.

cheers
DRB2k2
You using Visual Basic .NET?
drb2k2,

Immediately after the file open dialog has closed - in the form that launched the dialog do a :

    Me.Refresh

This will redraw the form and remove the open dialog.

JR
.NET? Yes that would account for my confusion.
dbr2k2, if that is so, you should be aware that there is a .NET area
Try a 'DoEvents' after calling the ShowOpen method.
OpenFileDialog is definitely a .NET class
Avatar of drb2k2

ASKER

ok i'll repost in the right area
thanks guys

DRB2k2
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of drb2k2

ASKER

Superb, thank you idle mind
and to JR2003 and bukko.
Sorry should have split points but was too late. If you post on the same question in vb.net i'll split the points between you.
Cheers
DRB2k2