LayoutControlExtension.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using DevExpress.Utils;
  2. using DevExpress.XtraEditors;
  3. using DevExpress.XtraLayout;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Drawing;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. using XdCxRhDW.Core;
  13. namespace ExtensionsDev
  14. {
  15. public static class LayoutControlExtension
  16. {
  17. public static void UseDefault(this LayoutControl ctrl)
  18. {
  19. ctrl.AllowTouchGestures = DevExpress.Utils.DefaultBoolean.False;
  20. ctrl.AllowDrop = false;
  21. ctrl.AllowCustomization = false;
  22. ctrl.OptionsFocus.AllowFocusGroups = false;
  23. ctrl.OptionsFocus.AllowFocusTabbedGroups = false;
  24. ctrl.OptionsFocus.AllowFocusControlOnLabelClick = true;
  25. ctrl.Root.GroupBordersVisible = false;
  26. System.Windows.Forms.Control findCtrl = ctrl;
  27. string GetLayoutName()
  28. {
  29. while (findCtrl.Parent != null)
  30. {
  31. findCtrl = findCtrl.Parent;
  32. if (findCtrl is System.Windows.Forms.UserControl) break;
  33. }
  34. return $"{findCtrl.Name}_{ctrl.Name}";
  35. }
  36. string name = GetLayoutName();
  37. (findCtrl as UserControl).Load += (sender, e) =>
  38. {
  39. var frm = ctrl.FindForm();
  40. if (frm != null)
  41. {
  42. frm.VisibleChanged += (sender2, e2) =>
  43. {
  44. Directory.CreateDirectory("Layout");
  45. if (name == null) return;
  46. ctrl.SaveLayoutToXml($"Layout\\{name}.xml");
  47. };
  48. }
  49. };
  50. if (name != null && File.Exists($"Layout\\{name}.xml"))
  51. {
  52. ctrl.RestoreLayoutFromXml($"Layout\\{name}.xml");
  53. }
  54. }
  55. }
  56. }