Control creation ("arrays") and inheritance

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.TabPages.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(genericSeriesTypes_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.
 
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
 
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
 
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/d...pref/html/frlrfsystemarrayclassclonetopic.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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top