C# 为 PictureBox 添加一个选项
我想知道如何将 .customString 添加到 PictureBox 对象。
比如:
PictureBox box = new PictureBox();
box.CustomString = "string here";
然后我就会访问它。
MessageBox.Show(boxname.CustomString);
谢谢。
i was wondering how could i add .customString to PictureBox object.
Something like:
PictureBox box = new PictureBox();
box.CustomString = "string here";
And then later on i would be access it.
MessageBox.Show(boxname.CustomString);
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您想向现有控件添加属性,最好的方法是从
PictureBox
派生MyCustomPictureBox
并将新属性添加到您的派生版本:If you want to add a property to an existing control the best way would be to derive
MyCustomPictureBox
fromPictureBox
and add the new property to your derived version:最简单的方法是使用
Tag
属性:然后:
The easiest way to do it is to use the
Tag
property:And, later:
现在,使用它会有点棘手。如果您通过在 Winforms 设计器中拖放来创建原始图片框,那么您必须进入 myform.designer.cs 文件,并将“PictureBox”实例替换为“MyPictureBox”
Now, using it will be a bit trickier. If you've created the original picturebox by drag'n'dropping it in the Winforms designer, then you'll have to go into the myform.designer.cs file, and replace the instances of "PictureBox" with "MyPictureBox"
您可以创建一个名为 MyPictureBox 的新类,它派生自 PictureBox。在新类中,您可以添加自定义属性。像下面这样的东西。
现在您可以像使用 PictureBox 一样使用新类,唯一的区别是您的类具有自定义属性/逻辑。
享受!
You could create a new class called MyPictureBox which derives from PictureBox. In the new class you can add your custom property. Something like the below.
Now you can use the new class just like you would the PictureBox only difference is the yours has the custom property / logic.
Enjoy!