91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

利用C#如何實現一個窗體抖動功能

發布時間:2020-11-25 14:56:21 來源:億速云 閱讀:172 作者:Leah 欄目:開發技術

今天就跟大家聊聊有關利用C#如何實現一個窗體抖動功能,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結了以下內容,希望大家根據這篇文章可以有所收獲。

原理:圍繞中心點運動一圈

利用C#如何實現一個窗體抖動功能

方法一:通過線程實現

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

具體代碼如下:

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);//設置執行完上一步停留時間
        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);
      }
    }
  }
}

方法二:通過計時器實現

需求:timer控件,button按鈕,for循環

具體代碼如下:

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

看完上述內容,你們對利用C#如何實現一個窗體抖動功能有進一步的了解嗎?如果還想了解更多知識或者相關內容,請關注億速云行業資訊頻道,感謝大家的支持。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

茌平县| 洞头县| 新营市| 望都县| 鄂伦春自治旗| 博爱县| 岗巴县| 彰武县| 垣曲县| 安康市| 兴宁市| 德惠市| 耿马| 新安县| 左云县| 南华县| 双城市| 碌曲县| 莆田市| 若尔盖县| 深泽县| 诸城市| 科技| 黄龙县| 沁源县| 嘉兴市| 夏津县| 陆良县| 茂名市| 上思县| 平昌县| 鲁甸县| 佛山市| 赤壁市| 原阳县| 新泰市| 凌海市| 木里| 荥经县| 修武县| 略阳县|