I have code that when you drag a child form within 5 of the parent one it docks. Then when you drag it out of the 5 it returns the size of the child form to what it started as....That works GREAT! But when you release the mouse the child form then goes back to the size it was when it was docked. You drag it again and it goes back to the creation size like I wanted until I release the mouse again! GGGAAAH!
I found a way to make it resize itself after I let go of the mouse but it grows likes it is docked then shrinks to the right size. Which is annoying because the screen flashes...
These are the two functions in the child form that control everything..
void FrmChildMove(object sender, EventArgs e)
{
// Determine the current location in parent form coordinates.
Point mouseAt = this.MdiParent.PointToClient(this.Location);
this.Text = "X: "+Convert.ToString(mouseAt.X)+ " - Y: "+Convert.ToString(mouseAt.Y);
// Determine if the floated is close enough to dock.
if (mouseAt.X < 5 && mouseAt.X > -5)
{
if ((Control.MouseButtons & MouseButtons.Left) == MouseButtons.Left)
{
dockTestAt = mouseAt;
// Reset the timer to poll for the MouseUp event.
tmrDock.Enabled = false;
tmrDock.Enabled = true;
}
}
else
{
//this controls shrinking the window back if you drag outside the 5
this.Dock = DockStyle.None;
this.Width = xx;
//this is the width, its saved when the form first loads, yy is the height
this.Height = yy;
}
}
// This is the tick function that keeps track of the mouse up
private void tmrDock_Tick(object sender, System.EventArgs e)
{
if (dockTestAt.X == this.MdiParent.PointToClient(this.Location).X
&& dockTestAt.Y == this.MdiParent.PointToClient(this.Location).Y)
{
if (Control.MouseButtons == MouseButtons.None)
{
// Dock in place.
tmrDock.Enabled = false;
this.Dock = DockStyle.Left;
}
}
else
{
// Mouse has moved. Disable this dock attempt.
tmrDock.Enabled = false;
this.Dock = DockStyle.None;
}
}
I am basing the code off of http://www.java2s.com/Code/CSharp/GUI-Windows-Form/MDIandDock.htm
It's annoying because I can't figure out why the child form goes back to the size of when it was docked when I release the mouse.