Monday, May 24, 2010

How do you load a second form in Visual Basic?

I'm trying to make a program for an online game i play to show the world map. It opens the first form with the main map and I want to be ablke to click on an image of say, an arrow, to go to the right. I made another form with what would be to the right but i can't figure out how to load that second form and get rid of the first one. any help appreciated. thanks.

How do you load a second form in Visual Basic?
(VB5/6) A simple way would be:





button_click() 'whatever you named the event button


form1.hide


form2.show





end sub





Change the form names to whatever you named them.
Reply:OK; first I asume you created a form class like this:





class Form1: Inherits System.Windows.Forms.Form


public sub new()


Me.size=new Size(400,400)


Me.FormBorderStyle = FormBorderStyle.None


Me.StartPosition=FormStartPosition.Cente...


Me.ShowDialog()


end sub


end class





Then you create


class Form2: Inherits System.Windows.Forms.Form


public sub new()


Me.size=new Size(400,400)


Me.FormBorderStyle = FormBorderStyle.None


Me.StartPosition=FormStartPosition.Cente...


Me.ShowDialog()


end sub


end class





Then you instantiate Form1: dim f1= New Form1()


And when you want to get rid of this use this code:





f1.close()


then you show the second form:


dim f2= New Form2()





I hope it helps!
Reply:Do a .Hide and .Show to your two forms as another poster has already explained.





If you want the first form to still exist, but not be clickable, then when you do a .Show on the second form, add vbModal to the end, which means that the first one won't be clickable until the second form closes.





Hope this helps, best of luck to your project!


No comments:

Post a Comment