DragDrop-Support of PictureBox-Control

2019-07-20 17:38发布

问题:

After some searching i figured out how dragdrop is implemented for a picturebox. But there is one thing - the (inherited of course) allowdrop property isn't accessible from code or property window of picturebox class. So to make it work i added following line to my form-load:

((Control)pictureBox1).AllowDrop = true;

Why do i have to do that? In msdn it says: "This API supports the .NET Framework infrastructure and is not intended to be used directly from your code."

Any explanation appreciated and sorry for my grammar ;)

回答1:

The PictureBox class overrides the property and adds

[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] 

This prevents it from being shown in IntelliSense.
However, you can still set the property without casting.

Microsoft does this when a property doesn't apply to a control. (eg, PictureBox.Text)
I don't know why AllowDrop wouldn't apply to a PictureBox; the source doesn't mention anything.