Simple question

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

    #1

    Simple question

    I have 2 forms - Form1 and Form2

    I open Form2 from Form1 by doing this:

    dim frm as Form2
    frm=new Form2
    frm.ShowDialog

    I need to change the Button1.Text on the Form1 from Form2.
    I'm trying :
    dim frmCaller as Form1
    frmCaller=new Form1
    frmCaller.Butto n1.Text="Someth ing"

    The text of Button1 on Form1 doesn't change
    I suspect that I do not connect to the existing Form1, I just create a new
    instance of the Form1 and change Button1.Text in it. Because I see that in
    debug mode the text property is changed, but it's not on the screen.

    In VB6 assigning Caption of the Button from another form was pretty simple -
    Form1.Caption = "Something" . That's it.
    How is it done in VB2005?

    Thank you
    Al



  • Kerry Moorman

    #2
    RE: Simple question

    Al,

    Form2 needs a reference to Form1.

    One option is to create a property on Form2 similar to this:

    Public frmCaller as Form1

    Then, on Form1, supply the reference before showing Form2:

    dim frm as Form2
    frm=new Form2
    frm.frmCaller = Me
    frm.ShowDialog

    Now Form2 can click a button on Form1:

    frmCaller.Butto n1.Text="Someth ing"

    Kerry Moorman

    "Al" wrote:
    [color=blue]
    > I have 2 forms - Form1 and Form2
    >
    > I open Form2 from Form1 by doing this:
    >
    > dim frm as Form2
    > frm=new Form2
    > frm.ShowDialog
    >
    > I need to change the Button1.Text on the Form1 from Form2.
    > I'm trying :
    > dim frmCaller as Form1
    > frmCaller=new Form1
    > frmCaller.Butto n1.Text="Someth ing"
    >
    > The text of Button1 on Form1 doesn't change
    > I suspect that I do not connect to the existing Form1, I just create a new
    > instance of the Form1 and change Button1.Text in it. Because I see that in
    > debug mode the text property is changed, but it's not on the screen.
    >
    > In VB6 assigning Caption of the Button from another form was pretty simple -
    > Form1.Caption = "Something" . That's it.
    > How is it done in VB2005?
    >
    > Thank you
    > Al
    >
    >
    >
    >[/color]

    Comment

    • Al

      #3
      Re: Simple question

      Thanks a lot, Kerry
      It is what I was looking for.
      Al

      "Kerry Moorman" <KerryMoorman@d iscussions.micr osoft.com> wrote in message
      news:06E6F796-F083-4E27-937F-50F639076295@mi crosoft.com...[color=blue]
      > Al,
      >
      > Form2 needs a reference to Form1.
      >
      > One option is to create a property on Form2 similar to this:
      >
      > Public frmCaller as Form1
      >
      > Then, on Form1, supply the reference before showing Form2:
      >
      > dim frm as Form2
      > frm=new Form2
      > frm.frmCaller = Me
      > frm.ShowDialog
      >
      > Now Form2 can click a button on Form1:
      >
      > frmCaller.Butto n1.Text="Someth ing"
      >
      > Kerry Moorman
      >
      > "Al" wrote:
      >[color=green]
      >> I have 2 forms - Form1 and Form2
      >>
      >> I open Form2 from Form1 by doing this:
      >>
      >> dim frm as Form2
      >> frm=new Form2
      >> frm.ShowDialog
      >>
      >> I need to change the Button1.Text on the Form1 from Form2.
      >> I'm trying :
      >> dim frmCaller as Form1
      >> frmCaller=new Form1
      >> frmCaller.Butto n1.Text="Someth ing"
      >>
      >> The text of Button1 on Form1 doesn't change
      >> I suspect that I do not connect to the existing Form1, I just create a
      >> new
      >> instance of the Form1 and change Button1.Text in it. Because I see that
      >> in
      >> debug mode the text property is changed, but it's not on the screen.
      >>
      >> In VB6 assigning Caption of the Button from another form was pretty
      >> simple -
      >> Form1.Caption = "Something" . That's it.
      >> How is it done in VB2005?
      >>
      >> Thank you
      >> Al
      >>
      >>
      >>
      >>[/color][/color]


      Comment

      Working...