小菜来袭 2017-05-19 02:39 采纳率: 40%
浏览 1139
已采纳

c# 窗体实现抖动的功能 以下代码是抖动窗体 我想让它抖动label

Random ran = new Random((int)DateTime.Now.Ticks);
            Point point = this.Location;
            for (int i = 0; i < 37; i++)
            {
                this.Location = new Point(point.X + ran.Next(23) - 4, point.Y + ran.Next(23) - 4);
                System.Threading.Thread.Sleep(15);
                label1.Location = point;
             //   this.Location = point;
                System.Threading.Thread.Sleep(15);
            }

怎么改抖动label

  • 写回答

2条回答 默认 最新

  • 战在春秋 2017-05-19 03:13
    关注

    假设label控件名为: label1。
    可以如下:

                Random ran = new Random((int)DateTime.Now.Ticks);
                Point point = this.label1.Location;
                for (int i = 0; i < 37; i++)
                {
                    this.label1.Location = new Point(point.X + ran.Next(23) - 4, point.Y + ran.Next(23) - 4);
                    System.Threading.Thread.Sleep(15);
                }
    

    题目代码中this代表窗体。
    修改后用this.label1找到窗体上对应的label控件。

    其它代码不变就行。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?