这篇文章主要为大家详细介绍了C#仿QQ聊天窗口,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了C#实现QQ聊天窗口的具体代码,供大家参考,具体内容如下
效果图:
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();
}
int x, y;// x为窗体left,y为窗体top
private void Form1_Load(object sender, EventArgs e)
{
this.Location = new Point(Screen.PrimaryScreen.WorkingArea.Width / 2 - this.Width / 2, Screen.PrimaryScreen.WorkingArea.Height / 2 - this.Height / 2);
x = this.Left;
y = this.Top;
this.AcceptButton = button2; //按回车发送
textBox1.ReadOnly = true; // 禁止输入
textBox1.ScrollBars = ScrollBars.Vertical; //显示垂直滚动条
textBox1.Font = new Font("", 16);
textBox2.Font = new Font("", 16);
}
int t = 5, space = 10;// t为暂停时间,space为移动距离
//抖动
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)
{
// 记录超出文本框高度 最新消息显示
textBox1.AppendText(DateTime.Now + "\r\n" + textBox2.Text + "\r\n");
textBox2.Text = " ";// 文本框清空
}
}
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持得得之家。
沃梦达教程
本文标题为:C#仿QQ聊天窗口
![](/xwassets/images/pre.png)
![](/xwassets/images/next.png)
猜你喜欢
- c# 模拟线性回归的示例 2023-03-14
- 在C# 8中如何使用默认接口方法详解 2023-03-29
- C# 使用Aspose.Cells 导出Excel的步骤及问题记录 2023-05-16
- Unity Shader实现模糊效果 2023-04-27
- .NET CORE DI 依赖注入 2023-09-27
- Unity3D实现渐变颜色效果 2023-01-16
- Oracle中for循环的使用方法 2023-07-04
- WPF使用DrawingContext实现绘制刻度条 2023-07-04
- 如何使用C# 捕获进程输出 2023-03-10
- user32.dll 函数说明小结 2022-12-26