Customizable Command Line Key

I am trying to create a custom command button that, by default, sets the width and height for certain parameters. I have the following code:

public partial class myCommandButton : Button
{
    public magCommandButton()
    {
        InitializeComponent();

    }

    [DefaultValue(840)]
    public override int Width
    {
        get 
        {
            return base.Width;
        }
        set
        {
            base.Width = value;
        }
    }

    [DefaultValue(340)]
    public override int Height
    {
        get
        {
            return base.Height;
        }
        set
        {
            base.Height = value;
        }
    }

    protected override void OnPaint(PaintEventArgs pe)
    {
        base.OnPaint(pe);
    }
}

However, it will not compile because it tells me that I cannot redefine width or height. Can someone tell me if I am approaching this incorrectly, or if there is a way around this?

+3
source share
2 answers

Width and height are not virtual members (check the management class in Reflector ), so the easiest way is to override the DefaultSize property:

        protected override Size DefaultSize
        {
            get
            {
                return new Size(840, 340);
            }
        }

, DefaultSize. Control Reflector, , Height Width / . , - . DefaultSize.

0

-, , DefaultValueAttribute ! Windows Forms, , "" ; , DefaultValueAttribute, .

, :

  • DefaultSize ( @Jarek)

  • Size ( ).

+1

Source: https://habr.com/ru/post/1742662/


All Articles