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");
}
}
}
}
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");
}
}
}
}