欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

C#仿QQ聊天窗口

程序员文章站 2022-04-25 22:41:44
本文实例为大家分享了c#实现qq聊天窗口的具体代码,供大家参考,具体内容如下效果图:using system;using system.collections.generic;using system...

本文实例为大家分享了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# 聊天窗口