Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Smooth transitioning between forms

Status
Not open for further replies.

RebLazer

Programmer
Jun 7, 2002
438
0
0
US
I am writing a VB.NET Windows app. So far, I have two Windows Forms: [tt]MainMenu[/tt] and [tt]Edit_select[/tt]. Not surprisingly, MainMenu is the name of the startup form. In class MainMenu (but outside of any of its subroutines), I have the following:[tt]
Public Shared menu_form As New MainMenu[/tt]

In the [tt]Menu_Load[/tt] ("Handles MyBase.Load") of MainMenu, I have the following:[tt]
menu_form = Me
Edit_select.es_form.Hide()[/tt]

Then in class Edit_Select, I have this:
[tt]Public Shared es_form As New Edit_select[/tt]

Here's my question: When that Hide() line executes, it's a very choppy transition between the two forms; the user can see one disappear, [pause], and the second form appear. Is there a smoother way to move from one form to the other?

Thanks very much,
Lazer
 
There must be some way to avoid this - I've never seen it in professionally written apps...
 

Please supply more info, clarify.
Why are you switching forms, what is the purpose of the application?

Give examples of the 'professionally written apps' that accomplish what you can not.

I would attempt an answer but I'm not sure what you're trying to do.

____________________________________________________
There are two ways to live your life. One is as though nothing is a miracle. The other is as though everything is a miracle. - Albert Einstein
 
Try inserting an
Code:
Application.DoEvents()
after the Hide call. This should allow the previous form to finish hiding before the next form is painted.
 
New to vb.net, but can you start the second form hidden or with a higer task number before the switch?

if it is to be it's up to me
 
Shelton,

The DoEvents sounded like a good idea, but unfortunately didn't work:[tt]

Private Sub mm_search_edit_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mm_search_edit_btn.Click
menu_form.Hide()
Application.DoEvents()
Edit_select.es_form.Show() 'declared earlier at the (Edit_select) class level as "Public Shared es_form As New Edit_select"
End Sub[/tt]

There's still a delay of more than a second where no form at all appears...



Paszt,
Background about my app may be found at the top of thread796-750784. The reason why I am switching forms is explained there, too. When I said 'professionally written' - I just meant that I've never seen a one or two second delay between screens - with nothing of the application being displayed in the interim - with any application before.



Infinitelo,
I haven't a clue how to do that...


Everyone,
Does what I am doing make sense altogether - namely declaring "Public Shared es_form " etc and then hiding and showing forms? Someone suggested using the opaque setting instead - but I supsect that will still allow buttons to be clicked even if they're not humanly visible (that's bad)...

Any ideas/suggestions are most welcome!!!


Thanks,
Lazer
 
This is a total shot in the dark but; one second sounds like an awful long time, are you processing something or establishing any kind of database connections in your form load?

If you are then all those routines must complete before the new form will paint. You should consider refactoring the form so it can load and activate before calling any other code.

Also if you're using any custom controls or something else you're not using elsewhere you may wany to test the form without those to see if they're causing the problem.
 
Stat792, thanks for your reply. There is nothing else that is being done. I have observed that when I do just a HIDE and then a SHOW - it takes a long time. Just those two commands in and of themselves...

The following is directed at no one in particular...
There absolutely must be a way to switch between two forms without such a delay!!!

This is just so frustrating!!!
[shocked][soapbox][curse][cry][bugeyed][flame]
I feel a little better now ...but am still just as stuck! :)

:-|
Lazer
 
Hmmm, have you tried showing the new form before hiding the old one?
 

Lazer,

Sorry, didn't mean to flame. I didn't know about the other thread, just trying to help.

I would suggest exactly what Stat792 just said, show the new form then hide the old.

Regards,

-Paszt
 
Paszt,

No, no, no - that was *not* directed at you! I really meant what I said when I wrote, "The following is directed at no one in particular..." I'm just frustrated. I do appreciate your help!

I'll post back if anything works. I'm now playing with having all the forms SHOW, but using visible=true/false to show and hide them...

Soon,
Lazer
 
One other thing(s), If you're using Visual Studio to develop, I've found that the initialization of forms is often very, very slow when run from the IDE. I assume this is due to the overhead of Visual Studio itself as well as the fact that you're in debug mode.

Have you tried running the compiled executable outside of the IDE?

You could load all forms at startup and hide all except for the one you need. This doesn't seem too professional.

Also you may want to try to put Me.Show() as the very first line in the form's Load event handler.

After reading your inital thread, I would have to agree with zarkon4. It seems that only one form is needed. As you said, each form is 99% identical. Each time you open a new form (with the Show method), you have to initialize the same controls. And since you don't close the first form (only hide it), it is still consuming resources.
Not that you shouldn't try to figure out this problem.

I just created two data forms each bound to a different database, included a button that opens the other form. I couldn't recreate your problem. It seems to take much less than a second to initalize and completely paint the form and all controls, even run from the IDE, even when I include connecting to the databases and loading the data as part of the load event handler. My databases are local. My computer is 1.6MHz with 512Mb RAM.

Hope this helps.

-Paszt
 
Paszt,

Yeah, I've tried running the EXE - it's no faster. I already have me.show() as the first line.

I'll just have to have a slow form transition... [cry]

Thanks very much for your help,
Lazer
 
I have an odd idea which I don't know if anyone gave. Why not display the second form, over the first form, THEN hide the first form? Unless you are running modal, you shouldn't have any issues. And there shouldn't be any "second or two where no form is visible at all." Give it a try and see if that fixes your problem.
 
AkutaSame,

It's not the HIDE that causes the delay - it's the SHOW command...

Thanks for trying ("please play again") :-|
Lazer
 
Humm.... You are creating each forms twice from what I can see.....

Let's try this

Dim objNewForm As New Edit_select
objNewForm.Show()
Me.Hide()

Then on the other form (Edit_select) in the onClose event...

Dim mParent As Form = Me.ParentForm
If Not (Me Is Nothing) Then
DirectCast(mParent, frmMain).show()
End If

Also... What is the exact event that you are using to call this Edit_select form?
 
I have been trying to do a similar thing, and there seems to be no easy way to do this in vb net, however, I have tracked down the following URL for my work and method 7 seems to be the closest to what you want.
 
Alpha20,

You've "been trying to do a similar thing" as what exactly? My problem is the 1 second (or so) delay in the transition between forms - not how to do it (as the article presents)...

?

Lazer
 
Hang on a minute.

Do you have a button on the main form that shows the second form? If so, then put the code that shows the second form under the button. This way the second form will appear over the main form, and you can then hide the main form. No one will see it, because it's behind the second form. I do this all the time.
If this does not work, then I would look into what is holding up the second form from showing? Is there a database command that must load while the second form is loading?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top