1

I would like to add a property to my form and have it show up in the designer.

I understand how to add a property to a custom control and have that visible in the designer, but it seems if I add a property directly to the form it is not showing up in the properties window.

I've seen articles that are close, but nothing seems to directly answer this question!

I've tried rebuilding the solution, loading/unloading project, tried a bunch of different design time attributes, tried using a private backing field.

namespace property_in_designer
{
public partial class Form1: Form
{
    public Form1()
    {
        InitializeComponent();

    }

    [Category("Layout")]
    [Description("Why Doesn't this show up in designer?")]
    [Browsable(true)]
    public int MyProp
    {
        get; set;
    } 
}
}

Any help is appreciated, thanks for reading!

Roxana Sh
  • 294
  • 1
  • 3
  • 14
Jeff M
  • 55
  • 4
  • I'm just wondering if its possible, since You want to add property to property window directly from code without compiling ? – Kuba Do Aug 27 '19 at 05:48
  • 1
    The Properties window shows the properties of the *base class*. So derive a class from Form1 and you get to edit MyProp. Project > Add New Item > Windows Forms node > Inherited Form. – Hans Passant Aug 27 '19 at 08:32
  • See an all-in-one implementation here: [How can I draw a rounded rectangle as the border for a rounded Form?](https://stackoverflow.com/a/56533229/7444103) – Jimi Aug 27 '19 at 10:44

1 Answers1

1

You have to create a user control that derives from Form, and include it in your project. The easiest way is to create a new class library, compile it, and add it as reference to your project. See here. enter image description here

Then, you can have it: enter image description here

Antoine
  • 148
  • 9