I’m making a custom window. When you resize a window from the left or the top, the window technically moves and resizes at the same time. I need to create this effect. I didnt post my code because its not even close, the window just jumps around the screen really fast… But here is the code I use for resizing and moving:
private void SetMousePosition(MouseEventArgs Position) {
MousePos = Position.Location;
}
private void SetRightPosition(MouseEventArgs Position) {
MouseDif = new Point(PointToClient(MousePosition).X - this.Width, PointToClient(MousePosition).Y - this.Height);
}
private void StartDrag(MouseEventArgs e) {
if (e.Button == MouseButtons.Left) {
int x = this.Left + e.X - MousePos.X;
int y = this.Top + e.Y - MousePos.Y;
this.Location = new Point(x, y);
}
}
private void StartRightResize(MouseEventArgs e) {
if (e.Button == MouseButtons.Left)
{
title.Text = PointToClient(MousePosition).X.ToString();
int x = PointToClient(MousePosition).X - MouseDif.X;
if (x < 60) x = 60;
this.Width = x;
}
}
This is the code I use just for dragging, and just for resizing from the right border. I just need to be able to use the left border to resize… I also need this to be able to work with a user control, and a custom window, i dont know id that makes sense though…
Have you tried the
SetBoundsmethod, which allows you to change size and position in a single operation? That should prevent the control from getting redrawn as often.Of course, you might need to make a picture of the control (
BitBlt), hide the control, and resize using that placeholder, then when the resize finishes, set the bounds of the real control and make it visible again.