[EditorAttribute(typeof(UITypeEditorWindowState), typeof(System.Drawing.Design.UITypeEditor))]
让我在编辑这个控件的时候,操作控件是UITypeEditorWindowState,如果我需要几个UITypeEditorWindowState那就得复制多个副本出来。如何在设置的时候传递一个值到UITypeEditorWindowState里去呢。
这样的话,我在UITypeEditorWindowState里就可以传递值到AngleControl里,再由此来设置OnPaint。如何?[CategoryAttribute("窗口属性"), DefaultValueAttribute(true), Description("窗口第一次打开方式")]
[EditorAttribute(typeof(UITypeEditorWindowState), typeof(System.Drawing.Design.UITypeEditor))] public String WindowState {
get { return AttrWindowState; }
set { AttrWindowState = value; }
}
public String AttrWindowState = "Normal"; public class UITypeEditorWindowState : System.Drawing.Design.UITypeEditor {
public UITypeEditorWindowState() {
}
public override System.Drawing.Design.UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context) {
return UITypeEditorEditStyle.DropDown;
} public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, System.IServiceProvider provider, object value) {
IWindowsFormsEditorService EdSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
if (EdSvc != null) {
AngleControl MySelect = new AngleControl((String)value);
EdSvc.DropDownControl(MySelect);
return MySelect.Result;
}
return "Normal";
}
}
internal class AngleControl : System.Windows.Forms.UserControl {
public String Result;
public AngleControl(String DataText) {
this.Result = DataText;
} protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) {
} protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e) {
} protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e) {
}
}

解决方案 »

  1.   

    在设计窗口,选择这个控件,可以获得一个新的自定义选项:WindowState UITypeEditorWindowState是这个自定义选项的操作方式。但是希望所有的自定义属性都是UITypeEditorWindowState。
    而不同的是由不同的UITypeEditorWindowState根据自定义属性来取得不同的属性,然后在创建AngleControl时,发送一个字符串过去,根据字符串产生UserControl样式。