Problem Using Multiple Forms

My problem is this, in VB6 one could add forms to a project and as long as he refered to the form in the code he could access the form and It's controls from controls on another form. VB.net seems to be different when I try to access a (Form2) I get messages like form2 is
not shared in the project or form2 is not part of thhe windows system.
if I declare the form on the same control that I'm going to use to change the form I can get Form2 to show but if I use it somewhere else I have to declare it there. Declaring it on the form1 load doesn't
seem to help. Is there some way to make a second form public throughout the project.


TNX Pantara27

Comments

  • There is but why would you want to break the rules of object orientation that Microsoft worked so hard to bring to VB in the first place? If you must revert to bad habits create a module (which suck ass but anyway) and create a public (read global - for those who like to use crappy global variables) and store a reference to your form there. Or while your at it why not create an entire collection of forms that are globally available and have access to all forms in your app at anytime without any concern for encapsulation.


    : My problem is this, in VB6 one could add forms to a project and as long as he refered to the form in the code he could access the form and It's controls from controls on another form. VB.net seems to be different when I try to access a (Form2) I get messages like form2 is
    : not shared in the project or form2 is not part of thhe windows system.
    : if I declare the form on the same control that I'm going to use to change the form I can get Form2 to show but if I use it somewhere else I have to declare it there. Declaring it on the form1 load doesn't
    : seem to help. Is there some way to make a second form public throughout the project.
    :
    :
    : TNX Pantara27
    :

  • : My problem is this, in VB6 one could add forms to a project and as long as he refered to the form in the code he could access the form and It's controls from controls on another form. VB.net seems to be different when I try to access a (Form2) I get messages like form2 is
    : not shared in the project or form2 is not part of thhe windows system.
    : if I declare the form on the same control that I'm going to use to change the form I can get Form2 to show but if I use it somewhere else I have to declare it there. Declaring it on the form1 load doesn't
    : seem to help. Is there some way to make a second form public throughout the project.
    :
    :
    : TNX Pantara27
    :

  • : My problem is this, in VB6 one could add forms to a project and as long as he refered to the form in the code he could access the form and It's controls from controls on another form. VB.net seems to be different when I try to access a (Form2) I get messages like form2 is
    : not shared in the project or form2 is not part of thhe windows system.
    : if I declare the form on the same control that I'm going to use to change the form I can get Form2 to show but if I use it somewhere else I have to declare it there. Declaring it on the form1 load doesn't
    : seem to help. Is there some way to make a second form public throughout the project.
    :
    :
    : TNX Pantara27
    :
    Try
    Dim N As New Form1
    '
    Me.Hide()
    'this line at end hides form2
  • : My problem is this, in VB6 one could add forms to a project and as long as he refered to the form in the code he could access the form and It's controls from controls on another form. VB.net seems to be different when I try to access a (Form2) I get messages like form2 is
    : not shared in the project or form2 is not part of thhe windows system.
    : if I declare the form on the same control that I'm going to use to change the form I can get Form2 to show but if I use it somewhere else I have to declare it there. Declaring it on the form1 load doesn't
    : seem to help. Is there some way to make a second form public throughout the project.
    :
    :
    : TNX Pantara27
    :
    ----------------------------
    Hi,

    There are two ways to make a form global.

    1. Add a module and create an object of the form, which u want to
    access globally.
    For eg., if u want form2 to be accessable globally, put the following
    code in your module.

    dim frm2 as new form2

    2. The same can be put next to the
    WINDOWS FORM GENERATED CODE (block), which makes the
    object global within that form alone.
    inside that form the controls present in the form2 can be
    accessed. But the same cannot be performed from other forms.


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories