Saeed mohammadi
Saeed mohammadi

Reputation: 319

How to avoid control right to left property be affected by container

How can I force a control right to left and font property (and other properties if they are affected) in C# or Vb.net not to be affected by their containers?

For example when I put a Textbox into a panel which it's font is "Font A", Textbox font property font becomes "Font A". How can I avoid this?

Upvotes: 2

Views: 274

Answers (1)

Sinatr
Sinatr

Reputation: 22008

To override property (so its value is not default for that control type and not taken from parent somehow) you can do following

[System.ComponentModel.DesignerCategory("Code")]
public class MyLabel : Label
{
    [DefaultValue(true)]
    public new bool AutoSize
    {
        get { return base.AutoSize; }
        set { base.AutoSize = value; }
    }

    public MyLabel()
    {
        AutoSize = true;
    }
}

Upvotes: 2

Related Questions