Reputation: 91
I have a custom Form with no borders and title bar. I`am using panel(width = 1px) to emulate borders. All work great, except left and top border. When I try to reduce the size of the form(by draging it to right side),it work fine BUT when the size of form == this.MinimumSize. It start moving to right side. I want only change size, withoust moving... Here my leftBorder code. How i can modify it to change only size?
private void borderW_MouseDown(object sender, MouseEventArgs e)
{
Active = true;
}
private void borderW_MouseMove(object sender, MouseEventArgs e)
{
if (Active)
{
if (e.X < 0)
{
this.Location = new Point(this.Left + e.X, this.Top);
this.Size = new Size(this.Width - e.X, this.Height);
}
else
{
this.Size = new Size(this.Width - e.X, this.Height);
this.Location = new Point(this.Left + e.X, this.Top);
}
}
}
private void borderW_MouseUp(object sender, MouseEventArgs e)
{
Active = false;
}
Upvotes: 1
Views: 243
Reputation: 1263
Paste this function in your form. It is an override that prevents the moving of the form.
However, you must fit it with a condition that makes it only active whenever the left of your form is the same as form.left + form.width(from what i understand from your question.
protected override void WndProc( ref Message m )
{
const int WM_NCLBUTTONDOWN = 161;
const int WM_SYSCOMMAND = 274;
const int HTCAPTION = 2;
const int SC_MOVE = 61456;
if ( (m.Msg == WM_SYSCOMMAND) && (m.WParam.ToInt32() == SC_MOVE) )
return;
if ( (m.Msg == WM_NCLBUTTONDOWN) && (m.WParam.ToInt32() == HTCAPTION)
)
return;
base.WndProc( ref m );
}
Upvotes: 2