C#仿QQ聊天窗口

 更新时间:2021年07月11日 10:16:18   作者:Dust_SongYunfei  
这篇文章主要为大家详细介绍了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#实现简单的JSON序列化功能代码实例

    C#实现简单的JSON序列化功能代码实例

    这篇文章主要介绍了C#实现简单的JSON序列化功能,大家可以参考使用
    2013-11-11
  • 在Linux上运行C#的方法

    在Linux上运行C#的方法

    这篇文章主要介绍了在Linux上运行C#的方法,实例分析了Linux平台下Mono软件包的应用技巧,以及在此基础之上的C#运行方法,具有一定的参考借鉴价值,需要的朋友可以参考下
    2014-12-12
  • C# 大小写转换(金额)实例代码

    C# 大小写转换(金额)实例代码

    C# 大小写转换(金额)实例代码,需要的朋友可以参考一下
    2013-03-03
  • C#简单实现发送socket字符串

    C#简单实现发送socket字符串

    这篇文章主要为大家详细介绍了C#简单实现socket字符串发送,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2018-09-09
  • 关于c#中枚举类型支持显示中文的扩展说明

    关于c#中枚举类型支持显示中文的扩展说明

    需求 : 枚举类型在界面显示的时候可以显示相应的中文信息, 这样界面对用户友好 . 场景 : 在一些业务中涉及到审核功能的时候, 往往有这几个状态 :未送审 , 审核中 ,审核通过, 驳回 . 这个时候我们会定义一个枚举类型来描述 :
    2013-03-03
  • c#实现服务器性能监控并发送邮件保存日志

    c#实现服务器性能监控并发送邮件保存日志

    这篇文章主要介绍了c#实现服务器性能监控并发送邮件保存日志的示例,代码分为客户端和服务端,客户端可安装为本地服务形式启动
    2014-01-01
  • C#控制台带参数程序源码编写实例讲解

    C#控制台带参数程序源码编写实例讲解

    像ipconfig /all 这样的CMD命令想必大家都知道,但是很多童鞋可能不知道怎么写这样的控制台带参数的程序,需要的朋友可以了解下
    2012-12-12
  • 详解C# wpf如何嵌入外部程序

    详解C# wpf如何嵌入外部程序

    实现嵌入各种窗口控件后,其实还会有一种需求:嵌入外部程序,我们有时可能需要嵌入一个浏览器或者或者播放器等一些已有的程序,下面我们就来看看具体操作吧
    2024-04-04
  • DevExpress之饼状图突出(Explode)设置实例

    DevExpress之饼状图突出(Explode)设置实例

    这篇文章主要介绍了DevExpress之饼状图突出(Explode)设置方法,以实例形式展示了饼状图突出设置的具体实现过程,非常具有实用价值,需要的朋友可以参考下
    2014-10-10
  • Url相对路径的问题总结

    Url相对路径的问题总结

    很多时候,我们在图片或者其他(a标签,flash)中指定链接的时候,我们需要选择是使用绝对路径,或者是相对路径.
    2012-11-11

最新评论