【问题标题】:Smooth resize for Windows FormWindows 窗体的平滑调整大小
【发布时间】:2019-04-30 12:31:35
【问题描述】:

我正在使用以下方法为带有 FixedSingle FormBorderStyle 的表单重新创建大小调整功能来更新大小/位置:

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

但是,当我尝试调整窗口大小时,我得到了很多伪像,特别是如果我以正确的速度调整大小,窗口看起来就像在屏幕上被“涂抹”了一样。我尝试过启用双缓冲,但似乎没有什么不同。

【问题讨论】:

  • 你在哪里打电话resizeBottom?它是调用一次还是作为动画调用?另见:stackoverflow.com/a/8776905/880990
  • 我在 MouseMoved 事件处理程序中调用它。

标签: winforms optimization resize


【解决方案1】:

我做了一些测试,得到的结果与使用以下代码以常规方式(通过用鼠标单击并拖动窗口边缘)调整表单大小时发生的情况非常相似:

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() 使表单立即重绘。

注意:我用了Cursor.Position.Y + 30,否则我只能把表格变小,因为如果我向下移动鼠标就会离开窗口。

【讨论】:

  • 这很好用,Update() 调用极大地改善了事情。
猜你喜欢
  • 1970-01-01
  • 2011-12-19
  • 2013-04-30
  • 2014-03-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-09
  • 1970-01-01
相关资源
最近更新 更多