Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Adding Controls At Run-Time
Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
GlobeTrotter




PostPosted: Wed Nov 23, 2005 6:37 pm   Post subject: Adding Controls At Run-Time

I want to be able to click a button that will in turn add more instances of a frame on each click. On my form, I have one frame already, index number 0. This is the code for the cmd_click procedure.

code:

    Load fraTextNum(fraTextNum.Count)
    fraTextNum(fraTextNum.Count - 1) = fraTextNum(0)
    With fraTextNum(fraTextNum.Count - 1)
        .Top = fraTextNum(fraTextNum.Count - 1).Top + fraTextNum(fraTextNum.Count - 1).Height + 30
        .Caption = "Text File #" & CStr(fraTextNum.Count)
        .Visible = True
    End With


It seems to work if I press it once, and it creates another one underneath it. However, when I try and press it again, it does not create a third instance. Any ideas why? I'm stumped.
Sponsor
Sponsor
Sponsor
sponsor
Brightguy




PostPosted: Wed Nov 23, 2005 9:47 pm   Post subject: Re: Adding Controls At Run-Time

Actually you're just creating them all in the same spot.

You're setting the new frame's Top to be fraTextNum(fraTextNum.Count - 1).Top + fraTextNum(fraTextNum.Count - 1).Height + 30, but fraTextNum(fraTextNum.Count - 1).Top was just set to the first frame's Top.

You probably want to add on the Top of the previous frame created instead, that is, fraTextNum(fraTextNum.Count - 2).Top
GlobeTrotter




PostPosted: Wed Nov 23, 2005 11:21 pm   Post subject: (No subject)

Thanks, that was stupid.

Now, what if I want to do the exact same thing for, say, a textbox but have the new instance of the textbox inside the frame I just created?

When I try and do it, the textbox I create is stuck inside the original frame. I can't really see any properties I can change at run-time to select the frame it should be in, could you help please?
Brightguy




PostPosted: Fri Nov 25, 2005 3:54 pm   Post subject: Re: Adding Controls At Run-Time

VisualBASIC:
Set Option1.Container = Frame1
Display posts from previous:   
   Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: