By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,479 Members | 1,197 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,479 IT Pros & Developers. It's quick & easy.

Control creation ("arrays") and inheritance

P: n/a
My application addes or deletes tab pahes at the user's discretion. On each
tab page are controls that must be duplicated. Here's a sample of my code:

chart_tabcontrol.TabPages.Add(1)
chart_tabcontrol.SelectedTab =
chart_tabcontrol.TabPages(chart_tabcontrol.TabPage s.Count - 1)
chart_tabcontrol.Refresh()
chart_tabcontrol.SelectedTab.Text = "Chart " &
chart_tabcontrol.TabPages.Count.ToString
Dim genericSeriesTypes_label As New Label
genericSeriesTypes_label.Left = chartSeriesTypes_label1.Left
genericSeriesTypes_label.Top = chartSeriesTypes_label1.Top
genericSeriesTypes_label.Size = chartSeriesTypes_label1.Size
genericSeriesTypes_label.TextAlign = chartSeriesTypes_label1.TextAlign
genericSeriesTypes_label.Font = chartSeriesTypes_label1.Font
chart_tabcontrol.SelectedTab.Controls.Add(genericS eriesTypes_label)
genericSeriesTypes_label.Text = "Chart Series Types:"
Note that I assign the property values of the original control to each
derived control. This was fine at first, except that I keep encountering
more properties that I need to accomodate, so the list just keeps growing.

Isn't there an easier way to grab every property at once, perhaps using
inheritance? I'm new to this concept and can't find any examples yet in text
or on Google; everything I've found so far just refers to either forms or
class modules.
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies

P: n/a
Randall,

A more sufficient method is creating your own method.

A little sample roughly typed here so watch typos or other errors

\\\
Private Sub SetControl(byval ToPlace as Control, byval Original as Control)
bla
bla
ToPlace.Left = Original.Left
etc
if typeof control is checkbox then
ToPlace.checkstate = Origianal.checkstate
end if
End sub
///

I hope this helps,

Cor
Nov 21 '05 #2

P: n/a
Ah, I didn't even think about a modular approach, and I should have! Thanks,
I'll use that method to simplify things.

But-- there's no way to clone a control and have the clone automatically
inherit the original control's properties? I could have sworn there was.

Randall

"Cor Ligthert [MVP]" wrote:
Randall,

A more sufficient method is creating your own method.

A little sample roughly typed here so watch typos or other errors

\\\
Private Sub SetControl(byval ToPlace as Control, byval Original as Control)
bla
bla
ToPlace.Left = Original.Left
etc
if typeof control is checkbox then
ToPlace.checkstate = Origianal.checkstate
end if
End sub
///

I hope this helps,

Cor

Nov 21 '05 #3

P: n/a
Randall,

But-- there's no way to clone a control and have the clone automatically
inherit the original control's properties? I could have sworn there was.


There is not any method to copy an object (this is not a clone method),
doing the first is calling making a deepcopy what means that you take all
the values from the object one by one a kind of what you in fact are doing
now. There where cloning is possible it gives you only a kind of master or
reference.

This is a sample of a clone statement where this is more or less written.
http://msdn.microsoft.com/library/de...clonetopic.asp

Of course you can make your own controls by inheriting the basic classes.
However in that case the control takes the properties from the class, not
from an already instanced object.

I hope this gives an idea,

Cor
Nov 21 '05 #4

P: n/a
That helped Cor, thanks.

I'm really surprised there's no method for doing what I'd like, such as:

Dim New NewControl as Control = Inherits(OldControl)

or somesuch.

Randall

"Cor Ligthert [MVP]" wrote:
Randall,

But-- there's no way to clone a control and have the clone automatically
inherit the original control's properties? I could have sworn there was.


There is not any method to copy an object (this is not a clone method),
doing the first is calling making a deepcopy what means that you take all
the values from the object one by one a kind of what you in fact are doing
now. There where cloning is possible it gives you only a kind of master or
reference.

This is a sample of a clone statement where this is more or less written.
http://msdn.microsoft.com/library/de...clonetopic.asp

Of course you can make your own controls by inheriting the basic classes.
However in that case the control takes the properties from the class, not
from an already instanced object.

I hope this gives an idea,

Cor

Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.