Search code examples
c#winformseventswindowmdi

Preventing a window from leaving MDI without twitching?


On my Form1's Move event, I check its position and if its out of the view of the user I move it back. Is there an event that fires when he is done moving it? Because the move event fires kind of while its being moved, I need it to be after its moved. Here is my code so far:

    private void PublicTicker_Move(object sender, EventArgs e)
    {
        if (this.Left < 0)
        { this.Left = 0; }

        else if (this.Left > this.MdiParent.ClientRectangle.Width - this.Width)
        { this.Left = this.MdiParent.ClientRectangle.Width - this.Width; }

        if (this.Top < 3)
        { this.Top = 3; }

        else if (this.Top > this.MdiParent.ClientRectangle.Height - this.Height)
        { this.Top = this.MdiParent.ClientRectangle.Height - this.Height; }
    }

Solution

  • Try performing your move correction routines in ResizeEnd event. Surprisingly it is fired not only when form is resized but also when form is moved by user.

    Read more Form.ResizeEnd Event.