Form level MouseDown and MouseUp events don't seem to be working....

J

JDeats

It appears the WinForm MouseDown and MouseUp event handlers are not
working properly. In the "bare bones" sample application below,
Form1_MouseUp gets called even through the mouse button remains
pressed while dragging the Form window to resize it.

Can this "problem" be explained as some sort of by-design behavior? If
so what is the work around to detecting when a user has completed
resizing a Windows Form by way of mouse drag?

/ Bare bones C# application to detect when user has completed a form
resize using mouse drag.
//
======================================================================
//
//
public partial class Form1 : Form
{
private int sizeHasChanged = 0;
private bool mouseDown = false;

public Form1()
{
InitializeComponent();

this.MouseDown += new MouseEventHandler(Form1_MouseDown);
this.MouseUp += new MouseEventHandler(Form1_MouseUp);

// resizeFinishedTimer is a .NET Timer control object
dropped onto the form in VS.NET designer
// It's Interval is set to 500 milliseconds
resizeFinishedTimer.Enabled = true;
}

void Form1_MouseUp(object sender, MouseEventArgs e)
{
mouseDown = false;

}

void Form1_MouseDown(object sender, MouseEventArgs e)
{
mouseDown = true;

}

private void Form1_SizeChanged(object sender, EventArgs e)
{
sizeHasChanged = 1;
}

private void resizeFinishedTimer_Tick(object sender, EventArgs
e)
{
if (!(mouseDown))
{
if (sizeHasChanged == 1)
{
sizeHasChanged = 0;
MessageBox.Show("Resize done");
}
}
}
}
 
P

Peter Duniho

It appears the WinForm MouseDown and MouseUp event handlers are not
working properly. In the "bare bones" sample application below,
Form1_MouseUp gets called even through the mouse button remains
pressed while dragging the Form window to resize it.

Can this "problem" be explained as some sort of by-design behavior?

Not sure. If there's anything odd about the behavior you're seeing, it's
that you get the mouse-down event at all, given that the mouse is being
clicked on the non-client area of the window. But that may well be by
design; you'd have to look at the native Win32 API to know for sure.
If
so what is the work around to detecting when a user has completed
resizing a Windows Form by way of mouse drag?

Maybe the Form.ResizeEnd event is what you're looking for? But I see that
you've already been given that as an answer.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top