Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

kind of a beginner question - how do i get Form1 to close itself after the user presses a "NEXT" button, and Form2 to open up. I would also like to send a parameter to Form2...

 

i would also appreciate advice on better ways of implementing the following:

in Form1 i ask the user to enter some info and then i do a query to the db to get the relevant matches. there could be multiple matches. i display those in a listbox. the user selects the one right match he wants and then clicks the "NEXT" button which is supposed to close Form1 and bring up Form2, while sending the info for the user's choice to Form2. Thus i was thinking of using listbox.selectedItem() to get the user choice and send it as a parameter to Form2... any better ideas of implementing the whole thing?

Posted

To close the form, you can use Me.Close or Me.Dispose. That would work unless the form you are trying to close is the Startup form. If you close the startup form, it will exit your application. If you are trying to close your startup form, you could hide the main form, but I'm not sure if thats good programming practice. And about sending data to another form, You could just pass whatever data you want in through the constructor. I don't see why that would be a problem. I've done it before on several occasions. You could even take the data you want passed and save it into a Class or Module. However, most would frown upon the use of Modules. Good luck.

 

-=Simcoder=-

Whatever thy hand findest to do, do it with all thy heart - Jesus
Posted

thanks!

 

so i guess from what you are saying that i cannot close the startup form and the following screens would just go on top of it?

 

i am also not able to figure out what syntax i would use to bring up Form2... i tried something like

Dim nxtScreen As Form2 = New Form2
or
Dim nxtScreen As Form2 = Form2.ActiveForm

 

but it doesn't work................... pls help...

Posted

last question - how would i pass a parameter to Form2?

(in java there would be parenthesis for the constructor, but no parens here...)

Posted

You pass them in the same way you do with Java or any other language. Here is a link that should be quite helpful.

Constructors

 

Basically you need to go into the Windows Generated Code and you should see something ilke that looks like this

 


 Public Sub New()
       MyBase.New()

       'This call is required by the Windows Form Designer.
       InitializeComponent()

       'Add any initialization after the InitializeComponent() call

   End Sub

 

You will copy and paste that code and then edit the part that says

 

Public Sub New()

 

And you will edit it with the parameters you want to pass in like this:

 

Public Sub New(ByVal Str As String)

 

You also need to add an initialization statement so the Constructor when done should look like this:

 

   Public Sub New(ByVal str As String)
       MyBase.New()

       'This call is required by the Windows Form Designer.
       InitializeComponent()

       'Add any initialization after the InitializeComponent() call
       Message = str
   End Sub

 

Note:The variable message was a global variable I declared at the top of my form

 

When you call your form from another form, you would pass in a string value using code something like this

 


Dim nxtScreen As New Form2("Hello") 
nxtScreen.ShowDialog()

 

I hope this code and the link proves to be useful. Sorry if you don't understand or if its confusing, just let me know. I'm the type of person who learns better by step by step example rather than reading some long tutorial and trying to go from there. Let me know.

 

-=Simcoder=-

Whatever thy hand findest to do, do it with all thy heart - Jesus
Posted
this is absoluely helpful -thanks! looks exactly like java - i guess i was confused by the lack of parenthesis for the call to the default constructor.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...