C#實(shí)現(xiàn)簡化QQ聊天窗口
本文實(shí)例為大家分享了C#實(shí)現(xiàn)簡化QQ聊天窗口的具體代碼,供大家參考,具體內(nèi)容如下
如圖樣式,詳細(xì)步驟如下

整個(gè)窗體設(shè)置
private void Form1_Load(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? this.BackColor = Color.Chocolate;//設(shè)置窗體背景顏色
? ? ? ? ? ? this.Text = "與張某正在聊天...";//設(shè)置窗體文本內(nèi)容
? ? ? ? ? ? this.Size = new Size(450,400);//設(shè)置窗體大小
? ? ? ? ? ? //設(shè)置窗體在工作區(qū)居中顯示
? ? ? ? ? ? this.Location = new ?Point(Screen.PrimaryScreen.WorkingArea.Width/2-this.Width/2,Screen.PrimaryScreen.WorkingArea.Height/2-this.Height/2) ;
? ? ? ? }添加兩個(gè)textbox分別為聊天內(nèi)容與輸入框;
添加兩個(gè)button分別為抖一抖與發(fā)送;
抖動(dòng)事件
private void button1_Click(object sender, EventArgs e)
? ? ? ? { ? //抖動(dòng)事件
? ? ? ? ? ? int x = this.Left;
? ? ? ? ? ? int y = this.Top;
? ? ? ? ? ? for (int n = 0; n < 3; n++)
? ? ? ? ? ? { ? ?//添加using System.Threading;
? ? ? ? ? ? ? ? this.Location = new Point(x - 3, y);
? ? ? ? ? ? ? ? Thread.Sleep(20);//掛起20毫秒
? ? ? ? ? ? ? ? this.Location = new Point(x - 3, y - 3);
? ? ? ? ? ? ? ? Thread.Sleep(20);
? ? ? ? ? ? ? ? this.Location = new Point(x, y - 3);
? ? ? ? ? ? ? ? Thread.Sleep(20);
? ? ? ? ? ? ? ? this.Location = new Point(x + 3, y - 3);
? ? ? ? ? ? ? ? Thread.Sleep(20);
? ? ? ? ? ? ? ? this.Location = new Point(x + 3, y + 3);
? ? ? ? ? ? ? ? Thread.Sleep(20);
? ? ? ? ? ? ? ? this.Location = new Point(x, y + 3);
? ? ? ? ? ? ? ? Thread.Sleep(20);
? ? ? ? ? ? ? ? this.Location = new Point(x - 3, y + 3);
? ? ? ? ? ? ? ? Thread.Sleep(20);
? ? ? ? ? ? ? ? this.Location = new Point(x - 3, y);
? ? ? ? ? ? ? ? Thread.Sleep(20);
? ? ? ? ? ? ? ? this.Location = new Point(x, y);
? ? ? ? ? ? }
? ? ? ? }發(fā)送事件
private void button2_Click(object sender, EventArgs e)
? ? ? ? { ? ?//發(fā)送時(shí)間
? ? ? ? ? ? if (textBox2.Text!="")//當(dāng)輸入欄不為空內(nèi)容時(shí)
? ? ? ? ? ? { ? //textbox1內(nèi)容等于textbox1原本內(nèi)容(聊天記錄)+現(xiàn)在的時(shí)間+發(fā)話人+textbox2的輸入內(nèi)容
? ? ? ? ? ? ? ? textBox1.Text = textBox1.Text + DateTime.Now + "\r\n" + "李某:"+textBox2.Text+"\r\n";
? ? ? ? ? ? ? ? textBox2.Text= "";//清空輸出框
? ? ? ? ? ? }
? ? ? ? }添加滾動(dòng)條
private void textBox1_TextChanged(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? //在textbox1屬性設(shè)置scrollbars滾動(dòng)條顯示
? ? ? ? ? ? //滾輪顯示最后一行
? ? ? ? ? ? this.textBox1.SelectionStart = this.textBox1.Text.Length;
? ? ? ? ? ? this.textBox1.ScrollToCaret();
? ? ? ? ? ? //設(shè)置lcon類型圖標(biāo)
? ? ? ? }
添加鍵盤事件
(Enter實(shí)現(xiàn)發(fā)送功能)
private void textBox2_KeyDown(object sender, KeyEventArgs e)
? ? ? ? { ?//在輸入框內(nèi)添加鍵盤事件,Enter實(shí)現(xiàn)發(fā)送功能
? ? ? ? ? ? if (e.KeyCode == Keys.Enter)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? button2_Click(sender, e);
? ? ? ? ? ? }
? ? ? ? }以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
c#中Winform實(shí)現(xiàn)多線程異步更新UI(進(jìn)度及狀態(tài)信息)
本篇文章主要介紹了c#中Winform實(shí)現(xiàn)多線程異步更新UI(進(jìn)度及狀態(tài)信息) ,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-02-02
C#實(shí)現(xiàn)的優(yōu)酷真實(shí)視頻地址解析功能(2014新算法)
這篇文章主要介紹了C#實(shí)現(xiàn)的優(yōu)酷真實(shí)視頻地址解析功能(2014新算法),本文在當(dāng)前環(huán)境下是有效的,因?yàn)閮?yōu)酷之前更新了算法,需要的朋友可以參考下2014-10-10
C#實(shí)現(xiàn)TIF圖像轉(zhuǎn)PDF文件的方法
這篇文章主要介紹了C#實(shí)現(xiàn)TIF圖像轉(zhuǎn)PDF文件的方法,涉及C#使用TIFtoPDF工具實(shí)現(xiàn)pdf文件轉(zhuǎn)換的技巧,需要的朋友可以參考下2015-07-07
C#操作本地文件及保存文件到數(shù)據(jù)庫的基本方法總結(jié)
C#使用System.IO中的文件操作方法在Windows系統(tǒng)中處理本地文件相當(dāng)順手,這里我們還總結(jié)了在Oracle中保存文件的方法,嗯,接下來就來看看整理的C#操作本地文件及保存文件到數(shù)據(jù)庫的基本方法總結(jié)2016-05-05
C# 漢字轉(zhuǎn)拼音(全拼和首字母)實(shí)例
這篇文章介紹了C# 漢字轉(zhuǎn)拼音(全拼和首字母)實(shí)例代碼,有需要的朋友可以參考一下2013-10-10

