Adding a control programmatically...

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

    #1

    Adding a control programmatically...

    I want to create a textbox programmaticall y and add the SAME textbox to
    to different panels. This code does not work:

    Dim tb As New TextBox
    tb.text = "xyz"
    Panel1.Controls .Add(tb)
    Panel2.Controls .Add(tb)

    The textbox gets added to Panel2, but not Panel1. How can i get the
    textbox to go to both panels? I can get it to work by duplicating the
    code block... one code block puts the textbox in Panel1 and the other
    one to Panel2. But i don't want to duplicate lots of code... i'd rather
    have it in one code block.

    Thanks!
    John

  • Stacey

    #2
    Re: Adding a control programmaticall y...

    Why would you add the same control to both panels? Create two different
    text boxes. Don't forget to assign their names (and I have found Tags useful
    for dynamic controls).. and assign each to the panels.
    "johnb41" <jsbuchmann@gma il.comwrote in message
    news:1160675684 .900742.106640@ m7g2000cwm.goog legroups.com...
    >I want to create a textbox programmaticall y and add the SAME textbox to
    to different panels. This code does not work:
    >
    Dim tb As New TextBox
    tb.text = "xyz"
    Panel1.Controls .Add(tb)
    Panel2.Controls .Add(tb)
    >
    The textbox gets added to Panel2, but not Panel1. How can i get the
    textbox to go to both panels? I can get it to work by duplicating the
    code block... one code block puts the textbox in Panel1 and the other
    one to Panel2. But i don't want to duplicate lots of code... i'd rather
    have it in one code block.
    >
    Thanks!
    John
    >

    Comment

    • johnb41

      #3
      Re: Adding a control programmaticall y...

      I really need to add the same "kind" of control to 2 different panels.
      The 2 panels need an identical interface.

      After reading your reply, i see the problem. 2 panels cannot have the
      EXACT same control. Each control is unique to itself. So i really do
      need to create separate controls and then add them to the panels.

      Thanks,
      John

      On Oct 12, 3:28 pm, "Stacey" <Stac...@commun ity.nospamwrote :
      Why would you add the same control to both panels? Create two different
      text boxes. Don't forget to assign their names (and I have found Tags useful
      for dynamic controls).. and assign each to the panels."johnb41 " <jsbuchm...@gma il.comwrote in messagenews:116 0675684.900742. 106640@m7g2000c wm.googlegroups .com...
      >
      I want to create a textbox programmaticall y and add the SAME textbox to
      to different panels. This code does not work:
      >
      Dim tb As New TextBox
      tb.text = "xyz"
      Panel1.Controls .Add(tb)
      Panel2.Controls .Add(tb)
      >
      The textbox gets added to Panel2, but not Panel1. How can i get the
      textbox to go to both panels? I can get it to work by duplicating the
      code block... one code block puts the textbox in Panel1 and the other
      one to Panel2. But i don't want to duplicate lots of code... i'd rather
      have it in one code block.
      >
      Thanks!
      John

      Comment

      Working...