【发布时间】:2013-06-05 01:34:13
【问题描述】:
对 PropertyGrid 控件进行了一些尝试,现在偶然发现了一个奇怪的问题。 我在一个位掩码的类中有一个 Uint32 属性。 所以我决定创建一个带有 32 个按钮的自定义下拉用户控件,以使 Uint32 可编辑。 这是类(没有按钮单击处理程序):
class MaskEditorControl : UserControl, IIntegerMaskControl
{
public MaskEditorControl()
{
InitializeComponent();
}
public UInt32 ModifyMask(IServiceProvider provider, UInt32 mask)
{
IWindowsFormsEditorService editorService = null;
if (provider != null)
editorService = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
if (editorService != null)
{
m_mask = mask;
checkBox0.CheckState = (m_mask & (1 << 0)) == 0 ? CheckState.Unchecked : CheckState.Checked;
checkBox1.CheckState = (m_mask & (1 << 1)) == 0 ? CheckState.Unchecked : CheckState.Checked;
checkBox2.CheckState = (m_mask & (1 << 2)) == 0 ? CheckState.Unchecked : CheckState.Checked;
editorService.DropDownControl(this);
}
return m_mask;
}
private UInt32 m_mask = 0;
}
ModifyMask(...) 是 IIntegerMaskControl 接口的实现函数,被另一个类调用:
public interface IIntegerMaskControl
{
UInt32 ModifyMask(IServiceProvider provider, UInt32 mask);
}
public class IntegerMaskEditor : UITypeEditor
{
public static IIntegerMaskControl control = null;
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.DropDown;
}
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
if (control == null)
return "Error: IIntegerMaskControl not set!";
return control.ModifyMask(provider, (UInt32)value);
}
}
这里是属性本身:
[System.ComponentModel.CategoryAttribute("Base")]
[Editor(typeof(IntegerMaskEditor), typeof(UITypeEditor))]
public UInt32 renderMask { get; set; }
它有效,但我的控件显示为白色(包括按钮),这看起来很不对劲。我不知道为什么。这是屏幕截图的链接:that is how the control looks like in action。 有人对为什么以及如何避免它有任何想法吗?我可以调用表单,但我宁愿坚持使用下拉菜单。
提前致谢!
【问题讨论】:
标签: controls custom-controls propertygrid