-
Adding controls at runtime
I am trying to create objects on a form at run time. I believe this is
possible although as usual MSDN is not very forthcoming about this subject.
Quite simply I would like to create and display additional textboxes at
run time on a form. This is done in response to the end user's commands
and so creating a lot of invisible controls at design time is not a valid
solution. Any help anyone can offer would be most appreciated. Thanks.
Chris
-
Re: Adding controls at runtime
"Chris Lucas" <cdl1051@earthlink.net> wrote in message
news:3b49c92c$1@news.devx.com...
>
> I am trying to create objects on a form at run time. I believe this
is
> possible although as usual MSDN is not very forthcoming about this
subject.
> Quite simply I would like to create and display additional textboxes at
> run time on a form. This is done in response to the end user's commands
> and so creating a lot of invisible controls at design time is not a valid
> solution. Any help anyone can offer would be most appreciated. Thanks.
Assuming VB6:
Make a module level Long variable, which we'll call m_lngControl. The point
of this variable is to allow us to generate non-repeating names.
Private m_lngControl As Long
Private Sub cmdAdd_Click()
Dim ctlAny As Control
m_lngControl = m_lngControl + 1
Set ctlAny = Controls.Add("VB.Textbox", "txt" & m_lngControl)
ctlAny.Visible = True
End Sub
-
Re: Adding controls at runtime
Worked like a champ, thanks very much Colin.
"Colin McGuigan" <cmcguigan@imany.com> wrote:
>
>"Chris Lucas" <cdl1051@earthlink.net> wrote in message
>news:3b49c92c$1@news.devx.com...
>>
>> I am trying to create objects on a form at run time. I believe this
>is
>> possible although as usual MSDN is not very forthcoming about this
>subject.
>> Quite simply I would like to create and display additional textboxes
at
>> run time on a form. This is done in response to the end user's commands
>> and so creating a lot of invisible controls at design time is not a valid
>> solution. Any help anyone can offer would be most appreciated. Thanks.
>
>Assuming VB6:
>
>Make a module level Long variable, which we'll call m_lngControl. The point
>of this variable is to allow us to generate non-repeating names.
>
>Private m_lngControl As Long
>
>Private Sub cmdAdd_Click()
> Dim ctlAny As Control
>
> m_lngControl = m_lngControl + 1
> Set ctlAny = Controls.Add("VB.Textbox", "txt" & m_lngControl)
> ctlAny.Visible = True
>End Sub
>
>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks