怎么用C#实现一个QQ聊天窗口

发布时间:2021-07-12 09:15:37 作者:Leah
来源:亿速云 阅读:108

这期内容当中小编将会给大家带来有关怎么用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聊天窗口了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注亿速云行业资讯频道。

推荐阅读:
  1. h5如何实现QQ聊天气泡
  2. python实现udp聊天窗口

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

上一篇:SpringBoot中怎么实现api加密

下一篇:怎么用Vue实现登录页面的动态粒子背景插件

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》