1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- using DevExpress.Utils;
- using DevExpress.XtraEditors;
- using DevExpress.XtraLayout;
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using XdCxRhDW.Core;
- namespace ExtensionsDev
- {
- public static class LayoutControlExtension
- {
- public static void UseDefault(this LayoutControl ctrl)
- {
- ctrl.AllowTouchGestures = DevExpress.Utils.DefaultBoolean.False;
- ctrl.AllowDrop = false;
- ctrl.AllowCustomization = false;
- ctrl.OptionsFocus.AllowFocusGroups = false;
- ctrl.OptionsFocus.AllowFocusTabbedGroups = false;
- ctrl.OptionsFocus.AllowFocusControlOnLabelClick = true;
- ctrl.Root.GroupBordersVisible = false;
- System.Windows.Forms.Control findCtrl = ctrl;
- string GetLayoutName()
- {
- while (findCtrl.Parent != null)
- {
- findCtrl = findCtrl.Parent;
- if (findCtrl is System.Windows.Forms.UserControl) break;
- }
- return $"{findCtrl.Name}_{ctrl.Name}";
- }
- string name = GetLayoutName();
- (findCtrl as UserControl).Load += (sender, e) =>
- {
- var frm = ctrl.FindForm();
- if (frm != null)
- {
- frm.VisibleChanged += (sender2, e2) =>
- {
- Directory.CreateDirectory("Layout");
- if (name == null) return;
- ctrl.SaveLayoutToXml($"Layout\\{name}.xml");
- };
- }
- };
-
- if (name != null && File.Exists($"Layout\\{name}.xml"))
- {
- ctrl.RestoreLayoutFromXml($"Layout\\{name}.xml");
- }
- }
- }
- }
|