I need to get the value of Image rectangle from Non public members of picturebox.
How to get that value?
Thanks in advance.
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.
Well, you could do it with reflection... but you shouldn't. It's not clear exactly what you mean by "value of Image rectangle" but you should definitely try to do all this through the public API. What are you trying to achieve? There may be a different way.
EDIT: Okay, now I see the property you're trying to access... you may be interested in this Connect issue filed in 2004. You're not the only one to want this... although whether you need it for the same reason or not, I don't know.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With