C#实现抖动消息框(winform框架)

mac2024-04-05  31

两个文本框,两个按钮

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 WindowsFormsApp1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { button1.Text = "抖动"; button2.Text = "发送"; this.Text = "聊天窗口"; x = this.Left; y = this.Top; } int x, y; int t = 10, space = 20; private void button1_Click(object sender, EventArgs e) { for(int i = 0; i < 5; i++) { this.Location = new Point(x - space, y); Thread.Sleep(t); this.Location = new Point(x - space, y - space); Thread.Sleep(t); this.Location = new Point(x, y - space); Thread.Sleep(t); this.Location = new Point(x + space, y - space); Thread.Sleep(t); this.Location = new Point(x + space, y); Thread.Sleep(t); this.Location = new Point(x + space, y + space); Thread.Sleep(t); this.Location = new Point(x, y + space); Thread.Sleep(t); this.Location = new Point(x - space, y + space); Thread.Sleep(t); this.Location = new Point(x - space, y); Thread.Sleep(t); this.Location = new Point(x,y); } } private void button2_Click(object sender, EventArgs e) { if(string.IsNullOrWhiteSpace(textBox2.Text)==false) { textBox1.Text += DateTime.Now + "\r\n" + textBox2.Text + "\r\n"; // 将现在的时间添加到发送的文本上面 textBox2.Text = " "; // 清空textbox2文本 } } private void textBox1_TextChanged(object sender, EventArgs e) { } } }
最新回复(0)