private void 聊天窗口_Load(object sender, EventArgs e)
{
//设置窗体在桌面的位置
this.Left = Screen.PrimaryScreen.Bounds.Width / 2 - this.Width / 2;
this.Top = Screen.PrimaryScreen.Bounds.Height / 2 - this.Height / 2;
textBox1.BackColor = Color.SkyBlue;//设置textbox1的颜色
textBox2.BackColor = Color.GreenYellow;//设置textbox2的颜色
this.BackColor = Color.Black;//设置窗体的颜色
//设置按钮的文本
button1.Text = "发送";
button2.Text = "抖动";
button3.Text = "关闭";
textBox1.ReadOnly = true;//设置输出为仅读
this.Opacity = 0.4;//设置不透明度
}
private void button1_Click(object sender, EventArgs e)
{
//设置文本内容不为空字符以及不能为空格
if (textBox2.Text.Trim() == "")//移除所有空白前导字符以及尾部字符
{
this.textBox2.Text = "";//设置为空
this.textBox2.Focus();//获取焦点
MessageBox.Show("发送内容不能为空,请至少包含一个字符!");
}
//第二种方法
//if (string.IsNullOrWhiteSpace(textBox2.Text))//指示指定的字符串是null,空还是仅有空白字符组成
//{
// this.textBox2.Text = "";
// this.textBox2.Focus();
// MessageBox.Show("发送内容不能为空,请至少包含一个字符!");
//}
else {
//获取textbox2内容在textbox1显示
textBox1.Text +="\r\n" + "{借愁哥哥(1848514604)}" + DateTime.Now + "\r\n" + "\r\n" + textBox2.Text + "\r\n";//设置发送时显示的发送人以及当前时间和输入的内容
textBox2.Text = "";
this.textBox2.Focus();//为textbox2设置焦点
}
}
private void button2_Click(object sender, EventArgs e)
{
int x= this.Left;
int y= this.Top;
//第一种方法timer解决
//for (int i = 0; i < 10; i++)
//{
// this.Location = new Point(x,y);
// this.Location = new Point(x-5,y);
// this.Location = new Point(x-5,y-5);
// this.Location = new Point(x,y-5);
// this.Location = new Point(x+5,y-5);
// this.Location = new Point(x+5,y);
// this.Location = new Point(x+5,y+5);
// this.Location = new Point(x,y+5);
// this.Location = new Point(x-5,y+5);
// this.Location = new Point(x-5,y);
// this.Location = new Point(x,y);
//}
//第二种方法之4个点
//for (int i = 0; i < 10; i++)
//{
// this.Location = new Point(x+10,y);
// Thread.Sleep(100);
// this.Location = new Point(x+10,y+10);
// Thread.Sleep(100);
// this.Location=new Point(x,y+10);
// Thread.Sleep(100);
// this.Location = new Point(x, y);
// Thread.Sleep(100);
//}
//第二种方法之9个点
for (int i = 0; i < 10; i++)
{
this.Location = new Point(x,y);
Thread.Sleep(10);
this.Location = new Point(x+10, y);
Thread.Sleep(10);
this.Location = new Point(x+10, y+10);
Thread.Sleep(10);
this.Location = new Point(x, y+10);
Thread.Sleep(10);
this.Location = new Point(x-10, y+10);
Thread.Sleep(10);
this.Location = new Point(x-10, y);
Thread.Sleep(10);
this.Location = new Point(x-10, y-10);
Thread.Sleep(10);
this.Location = new Point(x, y-10);
Thread.Sleep(10);
this.Location = new Point(x+10, y-10);
Thread.Sleep(10);
this.Location = new Point(x+10, y);
Thread.Sleep(10);
this.Location = new Point(x, y);
Thread.Sleep(10);
}
textBox1.Text+= "\r\n" + "{借愁哥哥(1848514604)}" + DateTime.Now + "\r\n" + "\r\n" + "对方向您发送了一条抖动消息" + "\r\n";
textBox2.Focus();//获取焦点
}
private void button3_Click(object sender, EventArgs e)
{
this.Close();//关闭此窗体
}
private void textBox1_TextChanged_1(object sender, EventArgs e)
{
//设置光标定位
this.textBox1.Focus();//为控件设置焦点
this.textBox1.Select(this.textBox1.TextLength, 0);//选择文本框中的文本范围,textlength为获取控件中文本长度
this.textBox1.ScrollToCaret();//将控件内容滚动到当前插入符号位置
}
private void textBox2_TextChanged_1(object sender, EventArgs e)
{
//设置textbox颜色
Random n = new Random();
textBox2.ForeColor = Color.FromArgb(n.Next(0, 255), n.Next(0, 255), n.Next(0, 255));
//textBox1.BackColor = textBox2.ForeColor;
this.Text = "正在输入...";
}
联系客服