以Winforms形式滑动

rs.*_*rs. 4 c# loops winforms

我正在屏幕底部制作一个表单,我希望它向上滑动,所以我编写了以下代码:

int destinationX = (Screen.PrimaryScreen.WorkingArea.Width / 2) - (this.Width / 2);
int destinationY = Screen.PrimaryScreen.WorkingArea.Height - this.Height;

this.Location = new Point(destinationX, destinationY + this.Height);

while (this.Location != new Point(destinationX, destinationY))
{
    this.Location = new Point(destinationX, this.Location.Y - 1);
    System.Threading.Thread.Sleep(100);
}
Run Code Online (Sandbox Code Playgroud)

但代码只是贯穿并显示结束位置而没有显示形式滑动,这就是我想要的.我尝试过Refresh,DoEvents - 任何想法?

Dav*_*vid 7

尝试使用Timer事件而不是循环.

  • @rs - 不是hacky,这是唯一的好办法.我很惊讶`DoEvents`不起作用,但真的这是一件好事,因为`DoEvents`是严重的hacky. (6认同)