DevExpress Winforms Controls 内置140多个UI控件和库,完美构建流畅、美观且易于使用的应用程序。
本文包含重大的更改信息,这些更改信息可能会影响WinForms Data Editors命名控件中使用两种未记录方法的更改信息。
在v20.1版本中,DoFormatEditValue和DoParseEditValue(在XtraEditors命名空间中)将不再是虚拟的,并且不再可以被覆盖。技术团队更是了两个技术示例,如果您在应用中使用此API,建议您在决定升级到v20.1时对代码进行同样的更改。
先前的执行:
protected override ConvertEditValueEventArgs DoFormatEditValue(object val) protected override ConvertEditValueEventArgs DoParseEditValue(object val)
当前实施:
protected override object DoFormatEditValue(object val, out bool handled) protected override object DoParseEditValue(object val, out bool handled)
请注意,不建议您重写这些新方法,请改用RaiseFormatEditValue和RaiseParseEditValue,这些方法引发相应的编辑事件,不太可能再次更改。
//version 19.2 and older protected override ConvertEditValueEventArgs DoFormatEditValue(object val) { ConvertEditValueEventArgs result = base.DoFormatEditValue(val); result.Value = MyFormatEditValue(result.Value); result.Handled = true; return result; } protected override ConvertEditValueEventArgs DoParseEditValue(object val) { ConvertEditValueEventArgs result = base.DoParseEditValue(val); result.Value = MyParseEditValue(result.Value); result.Handled = true; return result; } //version 20.1 and newer protected override void RaiseFormatEditValue(ConvertEditValueEventArgs e) { base.RaiseFormatEditValue(e);D e.Value = MyFormatEditValue(e.Value); e.Handled = true; } protected override void RaiseParseEditValue(ConvertEditValueEventArgs e) { base.RaiseParseEditValue(e); e.Value = MyParseEditValue(e.Value); e.Handled = true; } //Version 19.2 and older protected override ConvertEditValueEventArgs DoFormatEditValue(object val) { if(val is int) { switch((int)val) { case 0: return new ConvertEditValueEventArgs("zero"); case 1: return new ConvertEditValueEventArgs("one"); case 2: return new ConvertEditValueEventArgs("two"); case 3: return new ConvertEditValueEventArgs("three"); } } return base.DoFormatEditValue(val); } protected override ConvertEditValueEventArgs DoParseEditValue(object val) { if(val is string) { switch((string)val) { case "zero": return new ConvertEditValueEventArgs(0); case "one": return new ConvertEditValueEventArgs(1); case "two": return new ConvertEditValueEventArgs(2); case "three": return new ConvertEditValueEventArgs(3); } } return base.DoParseEditValue(val); } //Version 20.1 and newer protected override void RaiseFormatEditValue(ConvertEditValueEventArgs e) { base.RaiseFormatEditValue(e); if(e.Value is int) { e.Handled = true; switch((int)e.Value) { case 0: e.Value = "zero"; break; case 1: e.Value = "one"; break; case 2: e.Value = "two"; break; case 3: e.Value = "three"; break; } } } protected override void RaiseParseEditValue(ConvertEditValueEventArgs e) { base.RaiseParseEditValue(e); if(e.Value is string) { e.Handled = true; switch((string)e.Value) { case "zero": e.Value = 0; break; case "one": e.Value = 1; break; case "two": e.Value = 2; break; case "three": e.Value = 3; break; } } }
对于IRangeControlClient的自定义实现,您将需要用DevExpress.XtraEditors.RangeControlClientOrientation手动替换System.Windows.Forms.Orientation类型。
对于调度程序控件,将所有出现的System.Windows.Forms.KeyEventArgs和System.Windows.Forms.MouseEventArgs类型替换为相应的对应变量:DevExpress.Portable.Input.PortableKeyEventArgs和DevExpress.Portable.Input.PortableMouseEventArgs。
// Version 19.2 and earlier public class MyKeyboardHandlerService : KeyboardHandlerServiceWrapper { public override void OnKeyDown(KeyEventArgs e) { ... } } public class MyMouseHandlerService : MouseHandlerServiceWrapper { public override void OnMouseWheel(MouseEventArgs e) { ... } } // Version 20.1 and newer public class MyKeyboardHandlerService : KeyboardHandlerServiceWrapper { public override void OnKeyDown(PortableKeyEventArgs e) { ... } } public class MyMouseHandlerService : MouseHandlerServiceWrapper { public override void OnMouseWheel(PortableMouseEventArgs e) { ... } }
中国区首发 · DevExpress v20.1新版发布会报名开启,名额有限先到先得哦~
DevExpress技术交流群2:775869749 欢迎一起进群讨论
扫描关注DevExpress中文网微信公众号,及时获取最新动态及最新资讯