I'm trying to create a custom control that has about 20 labels on it, I want to make the fore-color of these labels read-only, and make them change with the fore color of the control instead of all individually. The same with the back color. I also need to know how to re-size the font size of these labels when the developer using the control re-sizes it in designer mode that way it's not just a bunch of empty space in the control.

public override Color ForeColor
{
get
{
return label1.ForeColor;
}

set
{
this.label1.ForeColor = value;
this.label2.ForeColor = value;
this.label3.ForeColor = value;
}
}

public override Color BackColor
{
get
{
return this.BackColor;
}

set
{
this.BackColor = value;
this.label1.BackColor = value;
this.label2.ForeColor = value;
this.label3.ForeColor = value;
}
}

But I don't know how to override the label colors to where they are read-only. Any help is appreciated.

Setting the controls private will not permit external access to them.
If you want to make their properties read only to external, then create properties in your control exposing the internals.

In properties, you can set get/set to a specific accessor (private, internal, protected, public,readonly, etc)

So,

private set{
this.label1.ForeColor = value;
this.label2.ForeColor = value;
this.label3.ForeColor = value;
}

Will probably do the trick.

As for resizing, you can use the SizeChanged event to trigger a method that dynamically changes font sizes. Hope this helps!

Edited 4 Years Ago by skatamatic: n/a

This article has been dead for over six months. Start a new discussion instead.