最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C#實(shí)現(xiàn)窗體抖動(dòng)的兩種方法

 更新時(shí)間:2020年11月24日 17:30:47   作者:英萊特——Dream  
這篇文章主要為大家詳細(xì)介紹了C#實(shí)現(xiàn)窗體抖動(dòng)的兩種方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了C#實(shí)現(xiàn)窗體抖動(dòng)的具體代碼,供大家參考,具體內(nèi)容如下

原理:圍繞中心點(diǎn)運(yùn)動(dòng)一圈

方法一:通過(guò)線程實(shí)現(xiàn)

需求:需要using System.Threading;命名空間和button按鈕以及for循環(huán)

具體代碼如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;//添加線程

namespace Test_Window_jitter
{
 public partial class Form1 : Form
 {
  public Form1()
  {
   InitializeComponent();
  }

  private void Form1_Load(object sender, EventArgs e)
  {
   this.Location = new Point(Screen.PrimaryScreen.WorkingArea.Width/2-this.Width/2,Screen.PrimaryScreen.Bounds.Height/2-this.Height/2);
   button1.BackgroundImage = Image.FromFile("../../img/1.jpg");
   button1.BackgroundImageLayout = ImageLayout.Stretch;
  }

  private void button1_Click(object sender, EventArgs e)
  {
   int x = this.Left;
   int y = this.Top;
   for (int i = 0; i < 3; i++)
   {
    this.Location = new Point(x - 3, y);
    Thread.Sleep(10);//設(shè)置執(zhí)行完上一步停留時(shí)間
    this.Location = new Point(x - 3, y - 3);
    Thread.Sleep(10);
    this.Location = new Point(x, y - 3);
    Thread.Sleep(10);
    this.Location = new Point(x + 3, y - 3);
    Thread.Sleep(10);
    this.Location = new Point(x + 3, y);
    Thread.Sleep(10);
    this.Location = new Point(x + 3, y + 3);
    Thread.Sleep(10);
    this.Location = new Point(x, y + 3);
    Thread.Sleep(10);
    this.Location = new Point(x - 3, y + 3);
    Thread.Sleep(10);
    this.Location = new Point(x - 3, y);
    Thread.Sleep(10);
    this.Location = new Point(x, y);
   }
  }
 }
}

方法二:通過(guò)計(jì)時(shí)器實(shí)現(xiàn)

需求:timer控件,button按鈕,for循環(huán)

具體代碼如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Test_Window_jitter
{
 public partial class Form2 : Form
 {
  public Form2()
  {
   InitializeComponent();
  }

  private void Form2_Load(object sender, EventArgs e)
  {
   this.Location = new Point(Screen.PrimaryScreen.WorkingArea.Width / 2 - this.Width / 2, Screen.PrimaryScreen.Bounds.Height / 2 - this.Height / 2);
  }

  private void button1_Click(object sender, EventArgs e)
  {
   timer1.Start();
  }

  private void timer1_Tick(object sender, EventArgs e)
  {
   int x = this.Left;
   int y = this.Top;
   for (int i = 0; i < 10; i++)
   {
    this.Location = new Point(x - 10, y);
    this.Location = new Point(x - 10, y - 10);
    this.Location = new Point(x, y - 10);
    this.Location = new Point(x + 10, y - 10);
    this.Location = new Point(x + 10, y);
    this.Location = new Point(x + 10, y + 10);
    this.Location = new Point(x, y + 10);
    this.Location = new Point(x - 10, y + 10);
    this.Location = new Point(x - 10, y);
    this.Location = new Point(x, y);
   }
   timer1.Stop();
  }
 }
}

看完記得點(diǎn)贊,下期更精彩!

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

永昌县| 清镇市| 伊金霍洛旗| 万年县| 太白县| 永嘉县| 罗定市| 昂仁县| 阿拉善左旗| 平利县| 张家口市| 奉新县| 钟祥市| 仁寿县| 清镇市| 舞阳县| 龙门县| 城口县| 吴旗县| 余干县| 甘洛县| 涿州市| 巍山| 南宫市| 宜黄县| 盖州市| 神农架林区| 贺州市| 普定县| 旅游| 绥芬河市| 昆山市| 沁水县| 江孜县| 额尔古纳市| 巴林右旗| 友谊县| 平邑县| 东港市| 浦城县| 乾安县|