I recently modified it. It is more convenient to use it on various forms.
The code is much simpler.
However, only the top left and right sides of the window are processed.
/// <Summary> /// hide the window dock class // usage // private FormDock formDock = null; // formDock = new FormDock (this, 300 ); /// </summary> public class FormDock {# region custom declaration // <summary> // defines the Timer // </summary> private Timer StopRectTimer = new Timer (); /// <summary> /// edge setting /// </summary> internal AnchorStyles StopAanhor = AnchorStyles. none; /// <summary> /// parent window instance /// </summary> private Form parentFor M = null; private Point m_TempPoiont; // private Point m_LastPoint; // coordinate point before the form is minimized # endregion # region constructor // <summary> // automatically dock /// </summary> /// <param name = "frmParent"> parent window object </param> public FormDock (Form frmParent) {parentForm = frmParent; parentForm. locationChanged + = new EventHandler (parentForm_LocationChanged); StopRectTimer. tick + = new EventHandler (timerrenttick); // register the event StopRectTimer. in Terval = 500; // timer execution cycle StopRectTimer. start (); // start the timer} // <summary> /// Automatic Stop // </summary> // <param name = "frmParent"> parent window object </ param> // <param name = "_ trimInterval"> clock period </param> public FormDock (Form frmParent, int _ trimInterval) {parentForm = frmParent; parentForm. locationChanged + = new EventHandler (parentForm_LocationChanged); StopRectTimer. tick + = new EventHandler (timerrenttick); // register the event Sto PRectTimer. interval = _ trimInterval; // timer execution cycle: StopRectTimer. start (); // Start timer execution} # endregion // <summary> // Start of the clock /// </summary> public void TimerStart () {StopRectTimer. start () ;}/// <summary> /// stop the clock /// </summary> public void TimerStop () {StopRectTimer. stop ();} # region Window Location change event // <summary> // window location change event // </summary> /// <param name = "sender"> </param> /// <param name = "e"> </param> priva Te void parentForm_LocationChanged (object sender, EventArgs e) {if (parentForm. location. X ==- 32000 & parentForm. location. Y =-32000) {m_LastPoint = m_TempPoiont; // minimized. m_LastPoint is the position before minimization.} Else {m_TempPoiont = parentForm. location;} this. mStopAnthor ();} # endregion # region timer cycle event // <summary> // timer cycle event // </summary> /// <param name = "sender"> </param >/// <param name = "e"> </param> private void timereffectick (object sender, eventArgs e) {if (parentForm. bounds. contains (Cursor. position) {this. formShow ();} else {this. formHide () ;}# endregion # Calculation of the location where the region window is docked /// <summary> // calculation of the location where the window is docked /// </summary> private void mStopAnthor () {if (parentForm. top <= 0) {StopAanhor = AnchorStyles. top;} else if (parentForm. left <= 0) {StopAanhor = AnchorStyles. left;} else if (parentForm. left> = Screen. primaryScreen. bounds. width-parentForm. width) {StopAanhor = AnchorStyles. right;} else {StopAanhor = AnchorStyles. none; }}# endregion # display the region form without adding edges /// <summary> // display the form without adding edges /// </summary> public void FormShow () {switch (this. stopAanhor) {case AnchorStyles. top: parentForm. location = new Point (parentForm. location. x, 0); break; case AnchorStyles. left: parentForm. location = new Point (0, parentForm. location. y); break; case AnchorStyles. right: parentForm. location = new Point (Screen. primaryScreen. bounds. width-parentForm. width, parentForm. location. y); break ;}# endregion # Hide the edge of the region form /// <summary> /// hide the form edge of the form /// </summary> private void FormHide () {switch (this. stopAanhor) {case AnchorStyles. top: if (parentForm. windowState = FormWindowState. minimized) {parentForm. location = this. m_LastPoint; break;} parentForm. location = new Point (parentForm. location. x, (parentForm. height-2) * (-1); break; case AnchorStyles. left: parentForm. location = new Point (-1) * (parentForm. width-2), parentForm. location. y); break; case AnchorStyles. right: parentForm. location = new Point (Screen. primaryScreen. bounds. width-2, parentForm. location. y); break ;}# endregion