C# Form Move Stopped Event
Asked Answered
B

5

7

Is there any event in C# that fires when the form STOPS being moved. Not while its moving.

If there is no event for it, is there a way of doing it with WndProc?

Biedermeier answered 31/5, 2009 at 20:34 Comment(0)
W
19

The ResizeEnd event fires after a move ends. Perhaps you could use that.

Wondering answered 31/5, 2009 at 21:21 Comment(2)
There is one problem with this solution. If moved by changing form's coordinates, this event isn't fired.Azpurua
Also if the Window State ChangesRollick
K
2

This is not a failsafe solution, but it's pure .NET and it's dead simple. Add a timer to your form, set it to a relatively short delay (100-150 ms seemed OK for me). Add the following code for the Form.LocationChanged and Timer.Tick events:

private void Form_LocationChanged(object sender, EventArgs e)
{
    if (this.Text != "Moving")
    {
        this.Text = "Moving";
    }
    tmrStoppedMoving.Start();
}

private void Timer_Tick(object sender, EventArgs e)
{
    tmrStoppedMoving.Start();
    this.Text = "Stopped";
}

If you want more exact handling (knowing exactly when the mouse button is release in the title bar and such) you will probably need to dive into monitoring windows messages.

Kirbykirch answered 31/5, 2009 at 21:15 Comment(1)
For anyone coming here and wanting to know a little more about the last part of this answer (Determining when the mouse is pressed and released during a move), check out my question which delves a little more into that #24493667Gentlemanatarms
I
2

I had the same problem with a user control, but it does not have the ResizeEnd event. The solution, which worked is to override the WndProc method and listen for EXITSIZEMOVE.

See example here

Illuse answered 27/9, 2010 at 15:52 Comment(0)
M
0

Just set a flag to true when onmove events are fired. If a mouseup event happens and the flag is true, the form stopped being moved.

I admit this probably won't work in the case of a user moving a form via the keyboard, but that's pretty rare.

Mansour answered 31/5, 2009 at 20:44 Comment(2)
The MouseUp event is very unlikely to be fired since moving the form is typically done using the title bar, and mouse events are not raised for mouse operations in that area.Evidentiary
mouseup event doesnt fire if you move the form from the title bar partBiedermeier
P
0

I tested ResizeChanged event, and it works fine, however I don't know relation between move and resize, but it works for me

Prostyle answered 16/6, 2016 at 12:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.