Reputation: 987
I am recreating resize functionality for a Form with FixedSingle FormBorderStyle using the following methods to update the size/position:
private void resizeBottom()
{
this.SuspendLayout();
this.SetBoundsCore(this.Location.X, this.Location.Y, this.Width, Cursor.Position.Y - this.Location.Y, BoundsSpecified.Size);
}
…(other resize helpers)...
protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)
{
base.SetBoundsCore(x, y, width, height, specified);
this.ResumeLayout();
}
However, when I attempt to resize the window I get a lot of artefacts, particularly if I resize at just the right speed, it looks like the window is being ’smeared’ across the screen. I have tried enabling double buffering but it doesn’t seem to make a difference.
Upvotes: 0
Views: 495
Reputation: 112352
I made some tests and got a result very similar to what happens when you resize the form the regular way (by clicking and dragging a window edge with the mouse) with this code:
private void resizeBottom()
{
SetBounds(Location.X, Location.Y, Width, Cursor.Position.Y + 30 - Location.Y);
}
protected override void SetBoundsCore(int x, int y, int width, int height,
BoundsSpecified specified)
{
base.SetBoundsCore(x, y, width, height, specified);
Update();
}
Update()
makes the form to redraw instantly.
Note: I used Cursor.Position.Y + 30
, otherwise I can only make the form smaller, since the mouse leaves the window if I move down.
Upvotes: 2