When inheriting, for example, from FlowLayoutPanel, I prescribe properties in the constructor:

class myFlow : FlowLayoutPanel { public myFlow() { AutoSize = true; AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; } } 

in the designer, I throw this element onto a form and, for example, I want to return AutoSize = false. It seems to be changing and looking at the element on the form as needed, but after the rebuild and the closing-opening of the form designer, the property again has the value specified in the constructor. I tried override InitLayout, but the effect is the same. How to properly configure the components so that the designer can change them?

    1 answer 1

      [Browsable(true), EditorBrowsable(EditorBrowsableState.Always),DefaultValue(true) DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] public override bool AutoSize { get { return base.AutoSize; } set { base.AutoSize = value; } } 

    I peeped this code in the Panel sources from which FlowLayoutPanel inherits its AutoSize. The DefaultValue (true) parameter, which actually does what you need has already been added ... Its existence and the ability to use it has been found in the same Panel sources

    AutoSizeMode I think by analogy should work ... For correct work, you will need using System.ComponentModel;

    Accordingly, from the constructor, the setting of these property values ​​must be removed.

    • Thanks It works. First question - do I really need to prescribe such code for all the properties that I will ask (and there are quite a lot of them - I want to define my own style of display for monotony)? The second question is where did the source look? it would be useful to take a look at it yourself - kvvk
    • one
      1) Well, hike, yes. 2) I loaded the assembly in which the Panel is located in dotPeek and looked there. (any decompiler for .net will work, I think) - Alexey
    • one
      @kvvk 1) is not necessary, you can also add your own property, for example Style and depending on its value set the parameters of the other properties without overriding everything and everyone 2) the source code can be viewed here referenceource.microsoft.com - rdorn