Prevent Winforms Designer from Generating Property Values for Inherited Controls

前端 未结 4 1271
清酒与你
清酒与你 2020-12-10 08:24

I have a custom DataGridView, let\'s say as such:

public MyGridView : DataGridView
{
    public MyGridView()
    {
         BackgroundColor = Co         


        
4条回答
  •  旧时难觅i
    2020-12-10 09:25

    There is a simpler way to assign DefaultValue to Color:

    public class MyGridView : DataGridView
    {
        public MyGridView()
        {
            BackgroundColor = Color.Red;
        }
    
        [DefaultValue(typeof(Color), "Red")]
        public new Color BackgroundColor
        {
            get { return base.BackgroundColor; }
            set { base.BackgroundColor = value; }
        }
    }
    

提交回复
热议问题