I always wanted to have a small programming framework of my own. The previous method was to compile every form file into a DLL file and create a class when creating a form, then in this class
Create a new form, compile a DLL file, read the information in the DLL file through a function, including the form name and version, and finally show the form, weifenluo is used for show. winformsui. docking. It seems that there is no problem, but every time a new form is created, a corresponding class is required. How many hundred forms are there? The project will be amazing, so I gave up this practice. After some time of conception, the general framework structure came out. I compared the two projects with identical functions, compared with my current method, the former is 6 times larger than the latter.
First, I need to use dockcontent to dock the form, and then I need to use the xtraform style (irisskin2.dll is really not easy to use, the style is monotonous, once a style is applied, the attributes of the control cannot be set. As we all know, it cannot be inherited. Therefore, write a class frmbase, which is roughly as follows:
Development document
1 using System; 2 using System.ComponentModel; 3 using System.Drawing; 4 using System.Windows.Forms; 5 using WeifenLuo.WinFormsUI.Docking; 6 7 namespace Allen.FrmBase 8 { 9 public class DockContent : XtraForm, IDockContent10 {11 public DockContent();12 13 [DefaultValue(true)]14 [Category("Category_Docking")]15 [Description("DockContent_AllowEndUserDocking_Description")]16 public bool AllowEndUserDocking { get; set; }17 [Category("Category_Docking")]18 [Description("DockContent_AutoHidePortion_Description")]19 [DefaultValue(0.25)]20 public double AutoHidePortion { get; set; }21 [Description("DockContent_CloseButton_Description")]22 [Category("Category_Docking")]23 [DefaultValue(true)]24 public bool CloseButton { get; set; }25 [DefaultValue(true)]26 [Description("DockContent_CloseButtonVisible_Description")]27 [Category("Category_Docking")]28 public bool CloseButtonVisible { get; set; }29 [Description("DockContent_DockAreas_Description")]30 [Category("Category_Docking")]31 public DockAreas DockAreas { get; set; }32 [Browsable(false)]33 public DockContentHandler DockHandler { get; }34 [Browsable(false)]35 public DockPanel DockPanel { get; set; }36 [Browsable(false)]37 public DockState DockState { get; set; }38 [Browsable(false)]39 public DockPane FloatPane { get; set; }40 [DefaultValue(false)]41 [Category("Category_Docking")]42 [Description("DockContent_HideOnClose_Description")]43 public bool HideOnClose { get; set; }44 [Browsable(false)]45 public bool IsActivated { get; }46 [Browsable(false)]47 public bool IsFloat { get; set; }48 [Browsable(false)]49 public bool IsHidden { get; set; }50 [Browsable(false)]51 public DockPane Pane { get; set; }52 [Browsable(false)]53 public DockPane PanelPane { get; set; }54 [Category("Category_Docking")]55 [Description("DockContent_ShowHint_Description")]56 public DockState ShowHint { get; set; }57 [Category("Category_Docking")]58 [Description("DockContent_TabPageContextMenu_Description")]59 [DefaultValue("")]60 public ContextMenu TabPageContextMenu { get; set; }61 [DefaultValue("")]62 [Category("Category_Docking")]63 [Description("DockContent_TabPageContextMenuStrip_Description")]64 public ContextMenuStrip TabPageContextMenuStrip { get; set; }65 public string TabText { get; set; }66 [Description("DockContent_ToolTipText_Description")]67 [Localizable(true)]68 [Category("Appearance")]69 [DefaultValue("")]70 public string ToolTipText { get; set; }71 [Browsable(false)]72 public DockState VisibleState { get; set; }73 74 [Description("Pane_DockStateChanged_Description")]75 [Category("Category_PropertyChanged")]76 public event EventHandler DockStateChanged;77 78 public void Activate();79 public void DockTo(DockPanel panel, DockStyle dockStyle);80 public void DockTo(DockPane paneTo, DockStyle dockStyle, int contentIndex);81 public void FloatAt(Rectangle floatWindowBounds);82 protected virtual string GetPersistString();83 public void Hide();84 public bool IsDockStateValid(DockState dockState);85 protected virtual void OnDockStateChanged(EventArgs e);86 public void Show();87 public void Show(DockPanel dockPanel);88 public void Show(DockPane pane, IDockContent beforeContent);89 public void Show(DockPanel dockPanel, DockState dockState);90 public void Show(DockPanel dockPanel, Rectangle floatWindowBounds);91 public void Show(DockPane previousPane, DockAlignment alignment, double proportion);92 }93 }
In each form file, the base class is inherited:
Public partial class frmmain: Allen. frmbase. dockcontent
Shows the key code:
In the future, if you want to do some small projects, simply apply this framework. You just need to add a form to it, save the corresponding path in the database, and the foreground will be ready to use it, all data operations use stored procedures. If any data exception occurs, you only need to modify the stored procedure and release the program on the client. This is much easier to maintain.