我想将一个对象设置为属性网格项,并带有一个弹出表单的按钮。没有按预期工作
所以我有一个属性网格,我想要绑定一个对象。当应用程序运行时,将出现一个按钮并显示一个表单,该表单将允许该对象设置其属性并返回到调用该表单的属性。
到目前为止,这是我所拥有的:
我无法让该属性显示在我的属性网格中。基本上我想使用一个表单来填写属性网格中的其他项目。
我希望我的问题足够清楚......
public class OptoSetupFormEditor : UITypeEditor
{
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.Modal;
}
public override object EditValue(ITypeDescriptorContext context, System.IServiceProvider provider, object value)
{
IWindowsFormsEditorService svc = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
DataTemp opto = value as DataTemp;
if (svc != null && opto != null)
{
using (OptoSigmaSetup form = new OptoSigmaSetup())
{
if (svc.ShowDialog(form) == DialogResult.OK)
{
opto.Direction = form.Direction;
opto.FunctionToCall = form.FunctionToCall;
opto.Duration = form.Duration;
// OptoSigmaTest.Command = form.
}
}
}
return opto; // can also replace the wrapper object here
}
}
[Editor(typeof(OptoSetupFormEditor),typeof(UITypeEditor))]
[TypeConverter(typeof(ExpandableObjectConverter))]
public DataTemp Test1
{
set
{
this.Duration = value.Duration ;
this.Direction = value.Direction;
this.FunctionUsed = value.FunctionToCall;
}
}
[ReadOnly(true), Category("Setup")]
public string FunctionUsed
{
get { return functionUsed; }
set { functionUsed = value; }
}
[ReadOnly(true), Category("Setup")]
public int Duration
{
get { return duration; }
set { duration = value; }
}
[ReadOnly(true),Category("Setup")]
public string Direction
{
get { return direction; }
set { direction = value; }
}
public class DataTemp
{
private int duration = 0;
private string direction = "Positive";
private string functionToCall = "Home";
public string FunctionToCall
{
get { return functionToCall; }
set { functionToCall = value; }
}
public int Duration
{
get { return duration; }
set { duration = value; }
}
public string Direction
{
get { return direction; }
set { direction = value; }
}
}
提前致谢。如果需要更多说明,请告诉我
So I have a property grid that I want to have an object bound to. When the application is running a button will show up and display a form which will allow that object to have its properties set and returned back to the property that called the form.
Here is what I have so far:
I cant get the property to show up in my property grid. Basically I want to use a form to fill in other items in the property grid.
I hope my question was clear enough...
public class OptoSetupFormEditor : UITypeEditor
{
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.Modal;
}
public override object EditValue(ITypeDescriptorContext context, System.IServiceProvider provider, object value)
{
IWindowsFormsEditorService svc = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
DataTemp opto = value as DataTemp;
if (svc != null && opto != null)
{
using (OptoSigmaSetup form = new OptoSigmaSetup())
{
if (svc.ShowDialog(form) == DialogResult.OK)
{
opto.Direction = form.Direction;
opto.FunctionToCall = form.FunctionToCall;
opto.Duration = form.Duration;
// OptoSigmaTest.Command = form.
}
}
}
return opto; // can also replace the wrapper object here
}
}
[Editor(typeof(OptoSetupFormEditor),typeof(UITypeEditor))]
[TypeConverter(typeof(ExpandableObjectConverter))]
public DataTemp Test1
{
set
{
this.Duration = value.Duration ;
this.Direction = value.Direction;
this.FunctionUsed = value.FunctionToCall;
}
}
[ReadOnly(true), Category("Setup")]
public string FunctionUsed
{
get { return functionUsed; }
set { functionUsed = value; }
}
[ReadOnly(true), Category("Setup")]
public int Duration
{
get { return duration; }
set { duration = value; }
}
[ReadOnly(true),Category("Setup")]
public string Direction
{
get { return direction; }
set { direction = value; }
}
public class DataTemp
{
private int duration = 0;
private string direction = "Positive";
private string functionToCall = "Home";
public string FunctionToCall
{
get { return functionToCall; }
set { functionToCall = value; }
}
public int Duration
{
get { return duration; }
set { duration = value; }
}
public string Direction
{
get { return direction; }
set { direction = value; }
}
}
Thanks in advance. If it needs more clarification, please let me know
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过使用
Browsable
属性来增强您希望显示的属性?,
编辑:
嗯,根据MSDN 没有此属性的属性,或者具有指定值为
true
的属性的属性,应显示在Property
窗口中;所以这是一个尚待完善的建议。Have you tried augmenting the properties you wish to display with the
Browsable
attribute?MSDN: BrowsableAttribute
EDIT:
Hm, according to MSDN, properties without this attribute, or those which have the attribute specified with a value of
true
, should display inProperty
windows; so this is a suggestion left wanting.