Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 150,220 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 2,163 people online right now. Registration is fast and FREE... Join Now!




I need to create a new button at runtime, and have it inherit the...

 
Reply to this topicStart new topic

I need to create a new button at runtime, and have it inherit the..., ...properties of a different button.

Kaysakado
4 Nov, 2007 - 09:19 AM
Post #1

New D.I.C Head
*

Joined: 4 Nov, 2007
Posts: 5


My Contributions
I've seen another topic on how to create objects at runtime, and understand how to do it, but I need the object to inherit the properties of another object. Here is my code:
CODE
Dim Button2 As New Button
        'Button2.Text = "testing"
        'Button2.Visible = True
        'Button2.Top = 20
        'Button2.Width = 100
        'Button2.Height = 50
        'Button2.Left = 10
        Controls.Add(Button2)
As you can imagine, it uses the default properties for a button, seeing as I've commented out the lines that set the properties.

This post has been edited by Kaysakado: 4 Nov, 2007 - 09:23 AM
User is offlineProfile CardPM
+Quote Post

EOgre0152
RE: I Need To Create A New Button At Runtime, And Have It Inherit The...
5 Nov, 2007 - 01:42 PM
Post #2

New D.I.C Head
*

Joined: 27 Apr, 2007
Posts: 13


My Contributions
Unless I am wrong you should be able to put in the code after what you already have lines like this:


button2.[property] = button1.[property]


Just put these lines in there for whatever properties you want (up to all of them). This may not be the leanest way to do it, but it should work
User is offlineProfile CardPM
+Quote Post

Kaysakado
RE: I Need To Create A New Button At Runtime, And Have It Inherit The...
6 Nov, 2007 - 03:05 PM
Post #3

New D.I.C Head
*

Joined: 4 Nov, 2007
Posts: 5


My Contributions
Well, I thought of doing that, but wanted to see if there was a more efficient way. Thanks anyways.
User is offlineProfile CardPM
+Quote Post

girasquid
RE: I Need To Create A New Button At Runtime, And Have It Inherit The...
6 Nov, 2007 - 03:28 PM
Post #4

Barbarbar
Group Icon

Joined: 3 Oct, 2006
Posts: 1,295



Thanked: 18 times
Dream Kudos: 725
My Contributions
This is just a guess/idea (that I haven't tested), but what about something like this?
CODE

dim button2 as new button = button1

And then you'd just adjust the properties that needed to be changed?
User is offlineProfile CardPM
+Quote Post

Kaysakado
RE: I Need To Create A New Button At Runtime, And Have It Inherit The...
6 Nov, 2007 - 06:29 PM
Post #5

New D.I.C Head
*

Joined: 4 Nov, 2007
Posts: 5


My Contributions
Nah, I get an "End of statement expected" error. It wants me to do something like the code below, and that would break it even worse.

CODE
Dim Button2 As New Button = Button1.text

User is offlineProfile CardPM
+Quote Post

girasquid
RE: I Need To Create A New Button At Runtime, And Have It Inherit The...
6 Nov, 2007 - 07:02 PM
Post #6

Barbarbar
Group Icon

Joined: 3 Oct, 2006
Posts: 1,295



Thanked: 18 times
Dream Kudos: 725
My Contributions
Oh, okay - I also found this topic on the MSDN forums which seems to be about the same thing...they seem to be saying that you'd need to create a separate function to take the button and return a new one with the same attributes.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 05:38AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month