![]() |
|
#1
|
|||
|
|||
|
i am making a program in visual basic and i requires me to open a new from from the appliction.. heres what im doing-
i made a lstbox and inside a few options... i want each of those options (when clicked) to open a new form i have premade but not already open... i HAVE made the forms i HAVENT got the coding so i dont know how to code it, help please?
|
|
#2
|
||||||||||||
|
||||||||||||
|
You need four lines at the right places.
__________________
Dim MyForm As FormName (somewhere at the start of the function you're calling it from) MyForm = New FormName() (makes you a new copy of the form in memory) MyForm.Show() (displays it in the window) MyForm = Nothing (wipes it from memory when you're finished with it) My System: Tim
|
|
#3
|
|||
|
|||
|
thanks i hope it works
|
|
#4
|
|||
|
|||
|
Before the .Show() you might want to set the x:y position to display it at, and maybe the size, and perhaps match the color. Any runtime attribute you want to change, that's where to do it. Then it shows up the way you expect it to.
|
|
#5
|
|||
|
|||
|
can you please post au much as you possibly can is they way i should type it please? i havent done this before!
thanx |
|
#6
|
|||
|
|||
|
There are far better tutorials than I could type from memory, I don't have Visual Basic to check against or copy bits from.
http://www.vb-helper.com/tutorial_sizing_forms.html shows the sort of code. The window you have at runtime has little to do with how it was when you were in design mode, the user has complete control of the size. If you're putting a new form into the window you could leave it where you designed it - that's easiest - or you could expand it to fit the space the user's given. |
|
#7
|
|||
|
|||
|
hmm... what i would do is create a timer that started when the form opens. then, with timer1_tick, it would check if the listbox was one of several choices.
|
|
#8
|
|||
|
|||
|
Double click on the listbox until the coding shows.
You should see: Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged End Sub Type this in the area above: If ListBox1.SelectedItem = "TheListBoxOptionText!" Then YourFormName!.Show() End If Then when your done it should look like! Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged If ListBox1.SelectedItem = "Show Form 1" Then Form2.Show() End If End Sub Tip: Visual Basic Is NOT about remembering its ALL about understanding! |
|
#9
|
|||
|
|||
|
thanks im trying it now
|
|
#10
|
|||
|
|||
|
thanks it works great
|