模仿窗口抖动发送

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 窗口抖动案列
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //设置窗口位置剧中
           this.Left =  Screen.PrimaryScreen.WorkingArea.Width/2-this.Width/2;
           this.Top = Screen.PrimaryScreen.WorkingArea.Height/2-this.Height/2;
            this.Text = "聊天窗口";
            //设置文本框是只读
            textBox1.ReadOnly = true;
            //使用回车发送
            this.AcceptButton = button2;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //窗口抖动
            int x = this.Left;
            int y = this.Top;
            for(int i = 0; i < 5; i++)
            {
                this.Location = new Point(x - 3, y);
                Thread.Sleep(20);
                this.Location = new Point(x - 3, y - 3);
                Thread.Sleep(20);
                this.Location = new Point(x, y - 3);
                Thread.Sleep(20);
                this.Location = new Point(x + 3, y - 3);
                Thread.Sleep(20);
                this.Location = new Point(x + 3, y);
                Thread.Sleep(20);
                this.Location = new Point(x + 3, y + 3);
                Thread.Sleep(20);
                this.Location = new Point(x, y + 3);
                Thread.Sleep(20);
                this.Location = new Point(x - 3, y + 3);
                Thread.Sleep(20);
                this.Location = new Point(x - 3, y);
                Thread.Sleep(20);
                this.Location = new Point(x, y);
                Thread.Sleep(20);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //消息发送
            if (textBox2.Text!="")
            {
                
                textBox1.AppendText ( DateTime.Now + "\r\n" + textBox2.Text + "\r\n");
                textBox2.Text = "";
                
            }
        }
    }
}

 

你可能感兴趣的:(模仿窗口抖动发送)