可以实现窗体的 吸附 移动 分离
- using System;
- using System.Drawing;
- using System.Collections.Generic;
- using System.Windows.Forms;
- namespace TinyBook
- {
- public enum MagneticLocation
- {
- Left = 0,
- Right = 1,
- Top = 2,
- Bottom = 3
- }
- public enum MagneticState
- {
- Adsorbent, // 吸附
- Separation // 分离
- }
- public class MagneticManager
- {
- public class ChildFormInfo
- {
- public Form Child { get; set; }
- public MagneticLocation Location { get; set; }
- public MagneticState State { get; set; }
- public bool CutstomSetLocation { get; set; }
- }
- public int Step { get; set; }
- private Form m_mainForm = null;
- private List<ChildFormInfo> m_childs= new List<ChildFormInfo>();
- public MagneticManager(Form form)
- {
- m_mainForm = form;
- form.LocationChanged += MainForm_LocationChanged;
- form.SizeChanged += MainForm_SizeChanged;
- form.FormClosed += MainForm_FormClosed;
- Step = 20;
- }