views:

70

answers:

1

I need to add some code to the EndInit method of a PictureBox control but unfortunately its private and, from what I can gather, I can't shadow it and call base - at least not in VB.Net.

What I can do is 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?

+1  A: 

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.

SLaks
I've added the DesignerSerializationVisibility.Content attribute but I still need my dummy class to derive from control. I'll try the code in c# and see if I get a different result.
Jules
I tested it in C# and the dummy class needed to inherit from Control. This seems a bit heavy handed but its possible that I don't need to inherit from Control but instead implement one of the many interfaces that control implements.
Jules
I'm pretty sure that all you need to inherit is `Component`.
SLaks
I've got it down to IComponent, that'll do for me. Cheers for the pointer.
Jules
Just to add, the DesignerSerializationVisibility.Content attribute is not needed unless you make the dummy property ReadOnly.
Jules
Check the designer code; it should be more efficient that way.
SLaks