multiple forms

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • iwdu15

    #1

    multiple forms

    hey, quick question for you, i have this code:

    [code language="vb"]
    Dim frm As Form
    frm.WindowState = FormWindowState .Normal
    [/code]

    and i have my form initialized and minimized so tis not that, but it gives
    me an error saying "object reference not set to an instance of an object".
    what am i doing wrong? any help would b awsome
  • Ken Tucker [MVP]

    #2
    Re: multiple forms

    Hi,

    In vb.net 2002 and 2003 that will not reference the open form. You
    need to have a reference to the form for it work or use the new keyword.

    dim frm as new form

    or

    dim frm as form = me

    Ken
    --------------
    "iwdu15" <iwdu15@discuss ions.microsoft. com> wrote in message
    news:916A87B1-6F4E-4136-A985-F0DB9BF91D49@mi crosoft.com...
    hey, quick question for you, i have this code:

    [code language="vb"]
    Dim frm As Form
    frm.WindowState = FormWindowState .Normal
    [/code]

    and i have my form initialized and minimized so tis not that, but it gives
    me an error saying "object reference not set to an instance of an object".
    what am i doing wrong? any help would b awsome


    Comment

    • Cor Ligthert [MVP]

      #3
      Re: multiple forms

      Ken,

      [color=blue]
      > dim frm as form = me
      >[/color]
      I have not seen this one before.

      Although that it is a little bit strange code, is it in my opinion a nice
      one, it explains direct what happens.

      Cor


      Comment

      • iwdu15

        #4
        Re: multiple forms

        Sry about my post, i made a typo, the code i have is as follows:

        Dim frm as form1
        frm.WindowState = FormWindowState .Normal

        and the rest is still true about it being initialized and such, sorry for
        the mistake

        Comment

        • Cor Ligthert [MVP]

          #5
          Re: multiple forms

          Idwu

          Probably you are searching for[color=blue]
          >
          > Dim frm as form1
          > frm.WindowState = FormWindowState .Normal
          >[/color]
          me.WindowState = FormWindowState .Normal

          If you have this kind of problems.
          Set it in the designer properties and than open the designer created code.
          That created code is mostly very nicely done.

          I hope this helps,

          Cor


          Comment

          • iwdu15

            #6
            Re: multiple forms

            kind of, i want to make the second form set to normal when the first form
            closes, so on the "form closing" event, i have that code there

            Comment

            • Cor Ligthert [MVP]

              #7
              Re: multiple forms

              iwdu

              In my opinion is the most simple way to do that to make one of the forms the
              owner than you can use in the other one

              me.owner.window state = etc.

              I hope this helps,

              Cor


              Comment

              • iwdu15

                #8
                Re: multiple forms

                i did that and made each form owned by the main form, but then when i try to
                say "me.owner.windo wstate = etc" it gives the error again

                Comment

                • Cor Ligthert [MVP]

                  #9
                  Re: multiple forms

                  Iwdu

                  How did you make it owned?

                  Cor


                  Comment

                  • iwdu15

                    #10
                    Re: multiple forms

                    Dim frm As New Brackets
                    Me.AddOwnedForm (frm)
                    frm.show()

                    Comment

                    • Cor Ligthert [MVP]

                      #11
                      Re: multiple forms

                      Iwdu,

                      I do it like this
                      \\\
                      dim frm as New Brackets 'assuming that this is a form
                      frm.owner = me
                      frm.show
                      ///

                      I hope this helps,

                      Cor


                      Comment

                      • iwdu15

                        #12
                        Re: multiple forms

                        i dont think the problem is with making it owner. i get the error at a
                        different time. i make form1 the owner of form "brackets", then in the
                        brackets form, when it closes, i try to have the owner's (form1) window state
                        be normal, not minimized and thats where i get the references error. this is
                        the code i use to try and change the window state:

                        Me.Owner.Window State = FormWindowState .Normal

                        and thats the line i get the error on

                        Comment

                        • Cor Ligthert [MVP]

                          #13
                          Re: multiple forms

                          Iwdu15

                          This below works for me withouth any problem

                          \\\
                          Private Sub Form1_Load(ByVa l sender As Object, _
                          ByVal e As System.EventArg s) Handles MyBase.Load
                          Dim frm As New Form2
                          frm.Owner = Me
                          frm.Show()
                          End Sub
                          ///
                          \\\
                          Private Sub Form2_Load(ByVa l sender As System.Object, ByVal e As
                          System.EventArg s) _
                          Handles MyBase.Load
                          Me.Owner.Window State = FormWindowState .Minimized
                          End Sub
                          ///

                          I hope this helps,

                          Cor


                          Comment

                          • iwdu15

                            #14
                            Re: multiple forms

                            ur gunna kill me but ends up my code was just in the wrong order, i had this:

                            close()
                            Me.Owner.Window State = FormWindowState .Normal

                            so it didnt have the form open that had an owner. well thanks a ton anyway!
                            il have ton of questions bc im a new programmer and like it alot so ive been
                            getting my hands on anything i can get, but thank you a ton

                            Comment

                            Working...