BaseEditExtension.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using DevExpress.XtraEditors;
  2. using DevExpress.XtraEditors.DXErrorProvider;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace ExtensionsDev
  11. {
  12. public static class BaseEditExtension
  13. {
  14. public static void UseDoubleClickToSelectAll(this BaseEdit ctrl)
  15. {
  16. ctrl.DoubleClick += Ctrl_DoubleClick;
  17. }
  18. private static void Ctrl_DoubleClick(object sender, EventArgs e)
  19. {
  20. var ctrl= (BaseEdit)sender;
  21. ctrl.SelectAll();
  22. }
  23. public static (bool,string) CheckLonLat(this TextEdit @this, string msg)
  24. {
  25. if (string.IsNullOrWhiteSpace(@this.Text.Trim()))
  26. {
  27. return (false, $"{msg}经纬度不能为空!");
  28. }
  29. var context = @this.Text.Split(',');
  30. if (context.Length != 2)
  31. {
  32. return (false,$"{msg}经度纬度之间用英文逗号隔开!");
  33. }
  34. double lon;
  35. bool isDoubleLon = Double.TryParse(context[0], out lon);
  36. if (!isDoubleLon || lon > 180 || lon < -180)
  37. {
  38. return (false, $"{msg}经度范围[180,-180]!");
  39. }
  40. double lat;
  41. bool isDoubleLat = Double.TryParse(context[1], out lat);
  42. if (!isDoubleLat || lat > 90 || lat < -90)
  43. {
  44. return (false, $"{msg}纬度范围[90,-90]!");
  45. }
  46. return (true,"");
  47. }
  48. }
  49. }