您好,登錄后才能下訂單哦!
本文小編為大家詳細(xì)介紹“怎么用C#代碼實(shí)現(xiàn)簡(jiǎn)化QQ聊天窗口”,內(nèi)容詳細(xì),步驟清晰,細(xì)節(jié)處理妥當(dāng),希望這篇“怎么用C#代碼實(shí)現(xiàn)簡(jiǎn)化QQ聊天窗口”文章能幫助大家解決疑惑,下面跟著小編的思路慢慢深入,一起來學(xué)習(xí)新知識(shí)吧。
如圖樣式,詳細(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); } }
讀到這里,這篇“怎么用C#代碼實(shí)現(xiàn)簡(jiǎn)化QQ聊天窗口”文章已經(jīng)介紹完畢,想要掌握這篇文章的知識(shí)點(diǎn)還需要大家自己動(dòng)手實(shí)踐使用過才能領(lǐng)會(huì),如果想了解更多相關(guān)內(nèi)容的文章,歡迎關(guān)注億速云行業(yè)資訊頻道。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。