Sign in to follow this  

[.net] Duplicating controls in VB.NET

This topic is 4838 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm working with VB.NET to create a simple Z80 assembly tool. What it has is a series of tab pages, each one with a text box on it. What I want to be able to do is have a Sub called "addTab" where I can pass 2 parameters - the filename, which appears on the tab button and the text for the source file. What it would then do is add a new tab (I can do that) and a new text box onto that tab with the source file text in it, so you can switch between the source files easily. To create a new textbox, I've tried
Dim x as New TextBox()
x = txtEditBox
...where txtEditBox is the existing text box which has all the properties set up. However, if I now add 'x' to a tab page, it'll actually move the txtEditBox to the tab page - I'm guessing because when I go x = txtEditBox it's copying a handle to the existing text box, rather than all its properties. Any hints, or ideas?

Share this post


Link to post
Share on other sites
Once you do:

Dim x as New TextBox()

you have a new textbox. Just add it to the tab page's control collection.

Dim tp As New TabPage()
Dim txt As New TextBox()

txt.Text = "Textbox " & TabControl1.Controls.Count + 1
tp.Controls.Add(txt)
tp.Text = "Page " & TabControl1.Controls.Count + 1

TabControl1.TabPages.Add(tp)

Share this post


Link to post
Share on other sites
Unfortunately that just creates it with the default properties - ideally I'd like to create it based on the properties of an existing one.
In VB6 you could just do Dim x as New txtSample, where txtSample was the text box with the properties you wanted to duplicate.

Share this post


Link to post
Share on other sites

This topic is 4838 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this