c#.net之窗体应用程序聊天窗口(抖动+发送)

c#.net之窗体应用程序聊天窗口(抖动+发送)_第1张图片

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.Location = new Point(Screen.PrimaryScreen.Bounds.Width/2-this.Width/2,
                Screen.PrimaryScreen.Bounds.Height/2-this.Height/2);
            this.Text = "聊天窗口";
            //设置Enter键
            this.AcceptButton = button1;
            //设置窗口不能拖拽
            this.AutoSizeMode = AutoSizeMode.GrowAndShrink;
            //设置只读
            textBox1.ReadOnly = true;
            //设置控件在容器内的Tab顺序
            textBox2.TabIndex = 0;
        }
        private void button2_Click(object sender, EventArgs e)
        {
            int x = this.Left;
            int y = this.Top;
            for (int i = 0; i < 4; 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);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox2.Text!="")
            {
                //向文本框的当前文本追加内容
                textBox1.AppendText(DateTime.Now + "\r\n" + textBox2.Text + "\r\n");
                textBox2.Text = "";
            }
        }

        private void 关闭ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}

你可能感兴趣的:(c#.net之窗体应用程序聊天窗口(抖动+发送))