[英]How do I make an image property in a winforms user control available in the properties window
On a winforms user control I've implemented I'd like to expose a property that allows a user to select an image that will be displayed on that control. 在我实现的winforms用户控件上,我想公开一个属性,该属性允许用户选择将在该控件上显示的图像。 I've tried exposing the property as both an Image and a Bitmap, I've tried specifying various attributes that looked promising, but no matter what I do, the property doesn't appear in the Properties window. 我尝试将属性同时显示为图像和位图,尝试尝试指定看起来很有希望的各种属性,但是无论我做什么,该属性都不会出现在“属性”窗口中。 What I'm looking for is the standard properties window interface that allows you to browse for an image to associate with the property. 我正在寻找的是标准属性窗口界面,该界面可让您浏览与属性关联的图像。 I suspect I'm going to kick myself for missing something obvious on this one, but I keep drawing a blank! 我怀疑自己会因错过这一明显的东西而踢自己,但我一直在画空白!
Here is an example that works for me: 这是一个对我有用的示例:
private Image image;
public Image Image
{
get
{
return image;
}
set
{
image = value;
}
}
After you add the code to the UserControl
, make sure you rebuild, then the Image property should appear in the Properties window. 将代码添加到UserControl
,请确保您进行了重建,然后Image属性应出现在Properties窗口中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.