Results 1 to 8 of 8

Thread: need help with dynamically adding a label

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2004
    Posts
    12

    need help with dynamically adding a label

    hi,

    i've created a scrollable form with several frames & even frames within other
    frames ( sub-frames?). anyway, things are fine up to this point.
    all frames (and design-time frame contents (labels, textboxes) get
    re-positioned correctly as the scroll bar is adjusted...

    problem is trying to add labels & textboxes to the frames that were added
    dynamically.

    they do not show up.

    any ideas w/o looking at the code?
    tia...

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: need help with dynamically adding a label

    You will have set Container property for each new control:

    Set Label3.Container = Frame3

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: need help with dynamically adding a label

    I would suggest that you use the SetParent API to place the textboxes and labels inside the dynamically created frame, but the problem is the labels don't have the necessary handle. You may need to create your own user control which contains your textboxes and labels and then dynamically add instances of the user control as needed.

  4. #4
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: need help with dynamically adding a label

    That's too much trouble Martin, isn't it ...

  5. #5
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: need help with dynamically adding a label

    Quote Originally Posted by RhinoBull
    You will have set Container property for each new control:

    Set Label3.Container = Frame3
    While that will move the label, I don't think you'll be able to see it once it's moved.

  6. #6
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: need help with dynamically adding a label

    Of course you will:

    NewLabel.Visible = True

  7. #7
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: need help with dynamically adding a label

    Here is a quick sample:
    VB Code:
    1. Private Sub Command2_Click()
    2. Dim lbl As Label
    3. Dim fra As Frame
    4.  
    5.     Set fra = Controls.Add("VB.Frame", "fraTemp")
    6.     fra.Move 500, 500, 6000, 3000
    7.     fra.Caption = "New Frame"
    8.     fra.ZOrder
    9.     fra.Visible = True
    10.    
    11.     Set lbl = Controls.Add("VB.Label", "lblTest")
    12.     Set lbl.Container = fra
    13.     lbl.Move 300, 300
    14.     lbl.Caption = "New Label"
    15.     lbl.AutoSize = True
    16.     lbl.Visible = True
    17.  
    18. End Sub

  8. #8

    Thread Starter
    New Member
    Join Date
    Sep 2004
    Posts
    12

    Re: need help with dynamically adding a label

    just curious, what happened to the reply from "hack"?

    chu

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width