ToolStripProgressBar RightToLeftLayout 设置属性问题
在这里,我尝试设置 ToolStripProgressBar 的 RIghtToLeftLayout 属性,当我尝试设置该值 true 或 false 时,我收到此错误.....
at System.Windows.Forms.ToolStripProgressBar.set_RightToLeftLayout(布尔值) 未将对象引用设置为对象的实例。
以下是代码:
PropertyInfo piRightToLeftLayout = ci.Type.GetProperty("RightToLeftLayout", typeof(bool));
if ((null != piRightToLeftLayout) && piRightToLeftLayout.CanWrite)
{
piRightToLeftLayout.GetSetMethod().Invoke(ci.Value, new object[] { IsRightToLeft() });
}
IsRightToLeft() :返回 true 或 false。
请帮我解决这个问题。
Here I'm trying to set the RIghtToLeftLayout property of ToolStripProgressBar, when i try to set the value either true or false, I'm getting this error.....
at System.Windows.Forms.ToolStripProgressBar.set_RightToLeftLayout(Boolean value)
Object reference not set to an instance of an object.
Here is the code:
PropertyInfo piRightToLeftLayout = ci.Type.GetProperty("RightToLeftLayout", typeof(bool));
if ((null != piRightToLeftLayout) && piRightToLeftLayout.CanWrite)
{
piRightToLeftLayout.GetSetMethod().Invoke(ci.Value, new object[] { IsRightToLeft() });
}
IsRightToLeft() : returns either true or false.
Please help me to resolve this issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你为什么要通过反思来做到这一点?
ToolStripProgressBar.RightToLeftLayout
是公共属性。就 NullReferenceException 而言,setter 所做的就是:
这意味着 ProgressBar 属性为 null,这看起来很奇怪。我想知道您在致电之前正在做什么以及
ci
是如何设置的。Why are you doing it by reflection?
ToolStripProgressBar.RightToLeftLayout
is a public property.In terms of your NullReferenceException, all the setter does is:
Which implies, the ProgressBar property is null, which seems odd. I'd like to know what you're doing prior to your call and how
ci
has been setup.