Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Visual Basic .NET (http://www.programmingforums.org/forum19.html)
-   -   How to link forms (http://www.programmingforums.org/showthread.php?t=12745)

humpa Mar 8th, 2007 8:42 AM

How to link forms
 
Hi im relatively new to visual basic and i was wondering if anybody could help me. I'm trying to open a second form when i click a button on the first form, what is the code to do that. My programming teacher is to dumb and doesn't know how, so maybe you all could help. Thanks!

Jimmy Bazooka Mar 8th, 2007 9:02 AM

I'll help you! :) Just drop VB and turn to C++. ;)

PhilBon Mar 8th, 2007 9:27 AM

Welcome to the Forums. Have you tried google-ing this? If not I suggest you do so. The next thing would be take up Jimmy's thought of learning C++. I will tell you this much. You create an object variable that references to the second form. So now you get to do some work and find out how to create a variable of an object of another form. It's quiet easy, I'll start it out for you: Dim mySecondForm as ___ _____ there you go, find out how to fill in those two blanks and you should be able to figure the rest out.

milot Mar 8th, 2007 11:36 AM

Hi,

I don't know Visual Basic but it's the same like in C#, so in C# I do something like shown below:

:

  1. private void button1_Click(object sender, EventArgs e)
  2. {
  3.               Form2 form_var = new Form2();
  4.               form_var.Show();
  5.               //form_var.ShowDialog();
  6. }


and I converted the above code to VB.NET using developerfusion utility http://www.developerfusion.co.uk/uti...sharptovb.aspx to make the conversion and the VB code should look like below:

:

  1. Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
  2. Dim form_var As Form2 = New Form2
  3. form_var.Show
  4. 'form_var.ShowDialog
  5. End Sub


As you can see I have commented .ShowDialog() method. With the .Show() method we can manipulate with two opened forms we can minimize Form1 work with Form2 or opposite, but when we use .ShowDialog() method, we cannot work in Form1 while the Form2 is shown, it is like a MessageBox we should close Form2 and continue working with Form1. But keep in mind, in our case here Form2 is child form of the Form1, so if you are using .Show dialog and if you close Form1 the Form2 will close.

If you have further questions, or I didn't express so good, post a reply we hare here for this reason to help each other ;).

kruptof Mar 8th, 2007 12:05 PM

Quote:

Originally Posted by Jimmy Bazooka (Post 124945)
I'll help you! :) Just drop VB and turn to C++. ;)

this was posted in the VB category, so obviously they are looking for an vb solution, and they did hint that they are studying this, i wonder what their lecturer would think if they handed in c++ code for an vb assignment

anyways...

i think you need to hide the current form and show the target form using the methods already provided by the forms:

currentform.hide
targetform.show

zorin Mar 8th, 2007 4:11 PM

Stop telling him to learn a new language, it has nothing to do with his question and is not appriciated.
Quote:

Originally Posted by humpa (Post 124941)
Hi im relatively new to visual basic and i was wondering if anybody could help me. I'm trying to open a second form when i click a button on the first form, what is the code to do that. My programming teacher is to dumb and doesn't know how, so maybe you all could help. Thanks!

In visual basic create a button and go to the form code and add the following: "Form2.Show". Now your code should look like
:

Private Sub Command1_Click()
Form2.Show
End Sub

Obviously the Private Sub Command1_click() will be different if you have more than one button present on your form. Hope that helps a little.

humpa Mar 9th, 2007 5:19 PM

Thanks alot everyone, well atleast everyone that helped me and didn't try to get me to learn C++. That's advanced programming in my school, and i'm not in that yet. Anyway thanks alot everyone you really helped!


All times are GMT -5. The time now is 10:40 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC