First: the wording of the question may be inaccurate, sorry for that. The actual question is below all code snippets.
Second: the code is in C#, but I usually write code in VB.NET.
I have a class LabelData which contains data for the visual appearence of a user drawn label. Short example:
public class LabelData
{
public Color BackColor1 { get; set; }
public Color BackColor2 { get; set; }
public Color TextColor { get; set; }
public int TextAngle { get; set; }
public string Text { get; set; }
}
My UserControl draws a lot of text (lets call them small labels) using LabelData. It looks like this (simplified):
public class UserControl1
{
public LabelData Title { get; set; }
protected override void OnPaint(PaintEventArgs e)
{
// draw title here
LabelData currentLabel;
for (int i = 0; i <= 9; i++)
{
currentLabel = new LabelData();
currentLabel.BackColor1 = Color.Green;
currentLabel.BackColor2 = Color.YellowGreen;
currentLabel.TextAngle = 0;
currentLabel.Text = "Element" + i.ToString();
// draw text here
}
}
}
All data for the small labels are defined within OnPaint. I don't want this. I thought of a Template for the smaller labels like the DataGridViewRowTemplate. This also allows me to implement ICloneable for LabelData.
This would change to:
public class UserControl1
{
public LabelData Title { get; set; }
public LabelData LabelTemplate { get; set; }
protected override void OnPaint(PaintEventArgs e)
{
LabelData currentLabel;
for (int i = 0; i <= 9; i++)
{
currentLabel = LabelTemplate.Clone();
currentLabel.Text = "Element" + i.ToString();
}
}
}
Now the question: How can I remove the Text-Property for the LabelTemplate property (but not for the Title property) in a PropertyGrid since this property changes in OnPaint anyways?
PS: I tried to create a custom designer and overwrite PreFilterProperties to remove the Text property, but I couldn't add a DesignerAttribute to the LabelTemplate property.
