欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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)一圈

方法一:通過線程實(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);
   }
  }
 }
}

方法二:通過計(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)贊,下期更精彩!

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

相關(guān)文章

  • c# WPF設(shè)置軟件界面背景為MediaElement并播放視頻

    c# WPF設(shè)置軟件界面背景為MediaElement并播放視頻

    這篇文章主要介紹了c# WPF如何設(shè)置軟件界面背景為MediaElement并播放視頻,幫助大家更好的理解和學(xué)習(xí)使用c#,感興趣的朋友可以了解下
    2021-03-03
  • 詳解Asp.Net MVC的Bundle捆綁

    詳解Asp.Net MVC的Bundle捆綁

    這篇文章主要介紹了Asp.Net MVC的Bundle捆綁方法,具體實(shí)現(xiàn)方法給大家做代碼整理,一起參考一下。
    2017-11-11
  • C#窗體讀取EXCEL并存入SQL數(shù)據(jù)庫的方法

    C#窗體讀取EXCEL并存入SQL數(shù)據(jù)庫的方法

    這篇文章主要介紹了C#窗體讀取EXCEL并存入SQL數(shù)據(jù)庫的方法,實(shí)例簡述了實(shí)現(xiàn)讀取excel及寫入SQL數(shù)據(jù)庫的原理與技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-01-01
  • C#實(shí)現(xiàn)IP代理池調(diào)度的示例代碼

    C#實(shí)現(xiàn)IP代理池調(diào)度的示例代碼

    這篇文章主要為大家介紹了C#實(shí)現(xiàn)IP代理池調(diào)度的相關(guān)知識(shí),文中的示例代碼講解詳細(xì),具有一定的參考與學(xué)習(xí)價(jià)值,感興趣的小伙伴可以了解一下
    2023-07-07
  • C#使用private font改變PDF文件的字體詳解

    C#使用private font改變PDF文件的字體詳解

    這篇文章主要給大家介紹了關(guān)于C#使用private font改變PDF文件的字體的相關(guān)資料,文中通過示例代碼以及圖片介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-07-07
  • WPF在VisualTree上增加Visual

    WPF在VisualTree上增加Visual

    這篇文章介紹了WPF在VisualTree上增加Visual的方法,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-06-06
  • C#如何實(shí)現(xiàn)調(diào)取釘釘考勤接口的功能

    C#如何實(shí)現(xiàn)調(diào)取釘釘考勤接口的功能

    這篇文章主要介紹了C#如何實(shí)現(xiàn)調(diào)取釘釘考勤接口的功能,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-08-08
  • C#微信公眾號(hào)開發(fā)之自定義菜單

    C#微信公眾號(hào)開發(fā)之自定義菜單

    這篇文章介紹了C#微信公眾號(hào)開發(fā)之自定義菜單,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-06-06
  • C#實(shí)現(xiàn)線段樹的示例代碼

    C#實(shí)現(xiàn)線段樹的示例代碼

    線段樹是一種常用來維護(hù)區(qū)間信息的數(shù)據(jù)結(jié)構(gòu),本文主要介紹了C#實(shí)現(xiàn)線段樹的示例代碼,具有一定的參考價(jià)值,感興趣的可以了解一下
    2023-11-11
  • Unity實(shí)現(xiàn)旋轉(zhuǎn)扭曲圖像特效

    Unity實(shí)現(xiàn)旋轉(zhuǎn)扭曲圖像特效

    這篇文章主要為大家詳細(xì)介紹了Unity實(shí)現(xiàn)旋轉(zhuǎn)扭曲圖像特效,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-02-02

最新評(píng)論