如何获得图片框的非公开成员的价值? [英] How to get the value of non- public members of picturebox?
本文介绍了如何获得图片框的非公开成员的价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要获得图像的矩形从图片框的非公共成员的值。
I need to get the value of Image rectangle from Non public members of picturebox.
如何获得这个值?
在此先感谢
推荐答案
这是如何得到的值,使用反射:
This is how to get the value, using reflection:
PropertyInfo pInfo = pictureBox1.GetType().GetProperty("ImageRectangle",
System.Reflection.BindingFlags.Public |
System.Reflection.BindingFlags.NonPublic |
System.Reflection.BindingFlags.Instance);
Rectangle rectangle = (Rectangle)pInfo.GetValue(pictureBox1, null);
虽然,作为乔恩说,有可能是实现你想要什么更好的方法做。通过反射访问私有成员通常是一个相当大的代码味道。
Although, as Jon has said, there may be a better way of achieving what you're trying to do. Accessing private members through reflection is usually a pretty big code smell.
这篇关于如何获得图片框的非公开成员的价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文