开发者

What are the requirments for ISupportInitialize code to be serialized in InitializeComponent? .NET

开发者 https://www.devze.com 2022-12-28 10:01 出处:网络
I need to add some code to the EndInit method of a PictureBox control, but unfortunately it\'s private and, from what I can gather, I can\'t shadow it and call ba开发者_JAVA技巧se - at least not in VB

I need to add some code to the EndInit method of a PictureBox control, but unfortunately it's private and, from what I can gather, I can't shadow it and call ba开发者_JAVA技巧se - at least not in VB.NET.

What I can do is to add a dummy property to my picture box class. The type of the dummy property is simply a class that just implements ISupportInitialize. However, that doesn't work, I need the dummy class to inherit from Control.

Is that the minimum requirement?


As you suspected, you need to make a proeprty that holds a dummy class implementing ISupportInitialize.

Then, expose the property like this:

[EditorBrowsable(EditorBrowsableState.Never)]  //Hide from IntelliSense (outside your solution)
[Browsable(false)]   //Hide from Properties window
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public MyDummyClass Initializer { get; private set; }

Specifying DesignerSerializationVisibility.Content will cause the designer to set the proeprties of the object instead of the object itself, and will also cause it to call BeginInit / EndInit.

Obviously, you should instantiate the class in your constructor.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号