欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#實現(xiàn)QQ聊天窗口

 更新時間:2022年02月11日 11:34:43   作者:Just?Do?Its  
這篇文章主要為大家詳細介紹了C#實現(xiàn)QQ聊天窗口,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了C#實現(xiàn)QQ聊天窗口的具體代碼,供大家參考,具體內(nèi)容如下

分析

  • 需要兩個TextBox,一個用于顯示消息,一個用于編輯消息
  • 需要四個按鈕,分別控制關(guān)閉程序,清空正在編輯的消息,發(fā)送消息,抖動

原理

1、在TextBox2中編輯消息并發(fā)送,在TextBox1中顯示所發(fā)送的消息的同時使TextBox2中的消息清空
2、發(fā)送的第一條消息TextBox1先保存并顯示,發(fā)送第二條消息時將TextBox1事先的消息先打印出來接著顯示第二條消息
3、抖動原理:使窗口的left以及top發(fā)生變化(圍繞窗體左上角為坐標(biāo)原點考慮)加上Thread線程和for循環(huán)從而實現(xiàn)窗口抖動效果

程序中用到的重要屬性

ReadOnly屬性:設(shè)置文本為只讀(true)textBox1.ReadOnly=true;

TabIndex屬性:設(shè)置光標(biāo)默認(rèn)出現(xiàn)在哪里(0)textBox1.TabIndex=0;

Multiline屬性:設(shè)置文本框可多行輸入textBox1.Multiline=true;

Datetime:獲取當(dāng)前時間

“\r\n” 換行

AcceptButton屬性:獲取或設(shè)置當(dāng)用戶按Enter鍵時所單擊的窗體上的按鈕this.AcceptButton = button2;

Thread類:創(chuàng)建和控制線程Thread.Sleep(10);//設(shè)置執(zhí)行完上一步停留時間還需要創(chuàng)建命名空間using System.Threading;

Trim方法:textBox2.Text.Trim()=="")//Trim:移除當(dāng)前textBox2對象位置前后的空白字符

具體代碼如下:

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;//設(shè)置多線程

namespace Test_QQ_chat_windows
{
? ? public partial class Form1 : Form
? ? {
? ? ? ? public Form1()
? ? ? ? {
? ? ? ? ? ? InitializeComponent();
? ? ? ? }

? ? ? ? private void Form1_Load(object sender, EventArgs e)
? ? ? ? {?
? ? ? ? ? ? //設(shè)置聊天窗口居中
? ? ? ? ? ? this.Left = Screen.PrimaryScreen.WorkingArea.Width / 2 - this.Width / 2;
? ? ? ? ? ? this.Top = Screen.PrimaryScreen.WorkingArea.Height / 2 - this.Height / 2;
? ? ? ? ? ? //聊天窗口命名
? ? ? ? ? ? this.Text = "和Know正在聊天";
? ? ? ? ? ? this.BackgroundImage = Image.FromFile("../../img/timg.jpg");//設(shè)置窗體背景圖
? ? ? ? ? ? this.BackgroundImageLayout = ImageLayout.Stretch;//設(shè)置窗體背景圖拉伸
? ? ? ? ? ? //textBox1設(shè)置只讀
? ? ? ? ? ? textBox1.ReadOnly = true;
? ? ? ? ? ? //設(shè)置發(fā)送按鈕可以用Enter鍵來觸發(fā)
? ? ? ? ? ? this.AcceptButton = button2;
? ? ? ? ? ? this.Opacity = 0.8;//設(shè)置窗體透明度為0.2
? ? ? ? ? ? textBox1.BackColor = Color.DeepSkyBlue;
? ? ? ? ? ? textBox2.BackColor = Color.DeepPink;
? ? ? ? }

? ? ? ? private void button1_Click(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? this.BackColor = Color.DeepSkyBlue;//設(shè)置窗體背景顏色
? ? ? ? ? ? textBox1.Text += "深夜食堂(36522224)" + DateTime.Now + "\r\n"+ "\r\n" + "您發(fā)送了一個窗口抖動" + "\r\n"+"\r\n";
? ? ? ? ? ? textBox2.Text = "";//設(shè)置發(fā)送內(nèi)容后textBox2中無內(nèi)容
? ? ? ? ? ? //窗口抖動
? ? ? ? ? ? int x = this.Left;
? ? ? ? ? ? int y = this.Top;
? ? ? ? ? ? for (int i = 0; i <= 3; i++)//設(shè)置抖動次數(shù)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? this.Location = new Point(x - 3, y);
? ? ? ? ? ? ? ? Thread.Sleep(10);//設(shè)置執(zhí)行完上一步停留時間
? ? ? ? ? ? ? ? this.Location = new Point(x - 3, y - 3);
? ? ? ? ? ? ? ? Thread.Sleep(10);
? ? ? ? ? ? ? ? this.Location = new Point(x, y - 3);
? ? ? ? ? ? ? ? Thread.Sleep(10);
? ? ? ? ? ? ? ? this.Location = new Point(x + 3, y - 3);
? ? ? ? ? ? ? ? Thread.Sleep(10);
? ? ? ? ? ? ? ? this.Location = new Point(x + 3, y);
? ? ? ? ? ? ? ? Thread.Sleep(10);
? ? ? ? ? ? ? ? this.Location = new Point(x + 3, y + 3);
? ? ? ? ? ? ? ? Thread.Sleep(10);
? ? ? ? ? ? ? ? this.Location = new Point(x, y + 3);
? ? ? ? ? ? ? ? Thread.Sleep(10);
? ? ? ? ? ? ? ? this.Location = new Point(x - 3, y + 3);
? ? ? ? ? ? ? ? Thread.Sleep(10);
? ? ? ? ? ? ? ? this.Location = new Point(x - 3, y);
? ? ? ? ? ? ? ? Thread.Sleep(10);
? ? ? ? ? ? ? ? this.Location = new Point(x, y);
? ? ? ? ? ? }
? ? ? ? }

? ? ? ? private void button2_Click(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? //消息發(fā)送
? ? ? ? ? ? //判斷textbox2中有無內(nèi)容
? ? ? ? ? ? if (textBox2.Text == ""||textBox2.Text.Trim()=="")//Trim:移除當(dāng)前textBox2對象位置前后的空白字符)
? ? ? ? ? ? {
? ? ? ? ? ? ? ?MessageBox.Show("輸入不能為空值,請重新輸入", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? {
? ? ? ? ? ? ?? ? textBox1.Text += "深夜食堂(36522224)" + DateTime.Now + "\r\n" + "\r\n" + textBox2.Text + "\r\n"+ "\r\n";
? ? ? ? ? ? ? ? textBox2.Text = "";//設(shè)置發(fā)送內(nèi)容后textBox2中無內(nèi)容
? ? ? ? ? ? }
? ? ? ? }

? ? ? ? private void button3_Click(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? this.Close();
? ? ? ? }

? ? ? ? private void button4_Click(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? textBox2.Text = "";
? ? ? ? }

? ? ? ? private void textBox1_TextChanged(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? //設(shè)置起始點在最后消息處
? ? ? ? ? ? this.textBox1.SelectionStart = this.textBox1.Text.Length;
? ? ? ? ? ? //內(nèi)容滾動到最后消息處
? ? ? ? ? ? this.textBox1.ScrollToCaret();
? ? ? ? }
? ? }
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • C#中的is和as操作符區(qū)別小結(jié)

    C#中的is和as操作符區(qū)別小結(jié)

    這篇文章主要介紹了C#中的is和as操作符區(qū)別小結(jié),is是驗證操作對象是不是自己希望的,as是將對象轉(zhuǎn)換成指定類型,需要的朋友可以參考下
    2015-01-01
  • ftp服務(wù)器搭建部署與C#實現(xiàn)ftp文件的上傳的示例

    ftp服務(wù)器搭建部署與C#實現(xiàn)ftp文件的上傳的示例

    本文主要介紹了ftp服務(wù)器搭建部署與C#實現(xiàn)ftp文件的上傳的示例,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-07-07
  • C#開發(fā)Winform實現(xiàn)窗體間相互傳值

    C#開發(fā)Winform實現(xiàn)窗體間相互傳值

    這篇文章介紹了C#開發(fā)Winform實現(xiàn)窗體間相互傳值的方法,文中通過示例代碼介紹的非常詳細。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-03-03
  • C#給PDF文件添加水印

    C#給PDF文件添加水印

    這篇文章主要為大家詳細介紹了C#給PDF文件添加水印的相關(guān)代碼,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-03-03
  • c# AES字節(jié)數(shù)組加密解密流程及代碼實現(xiàn)

    c# AES字節(jié)數(shù)組加密解密流程及代碼實現(xiàn)

    這篇文章主要介紹了c# AES字節(jié)數(shù)組加密解密流程及代碼實現(xiàn),幫助大家更好的理解和使用c#,感興趣的朋友可以了解下
    2020-11-11
  • c# 托盤雙擊不觸發(fā)單擊事件的實現(xiàn)方法

    c# 托盤雙擊不觸發(fā)單擊事件的實現(xiàn)方法

    在開發(fā)winform的時候我發(fā)現(xiàn),當(dāng)執(zhí)行雙擊操作(notifyIcon1_MouseDoubleClick)時,會同時伴隨著單擊事件(notifyIcon1_MouseClick)的發(fā)生。。那如何才能使雙擊事件不觸發(fā)單擊事件呢?
    2009-02-02
  • 基于Unity實現(xiàn)3D版2048游戲的示例代碼

    基于Unity實現(xiàn)3D版2048游戲的示例代碼

    這篇文章主要為大家詳細介紹了如何利用Unity實現(xiàn)簡易的3D版2048游戲,文中的示例代碼講解詳細,具有一定的學(xué)習(xí)價值,需要的可以參考一下
    2023-02-02
  • C#使用winform簡單導(dǎo)出Excel的方法

    C#使用winform簡單導(dǎo)出Excel的方法

    這篇文章主要介紹了C#使用winform簡單導(dǎo)出Excel的方法,結(jié)合實例形式分析了WinForm操作Excel文件的寫入導(dǎo)出等相關(guān)技巧,需要的朋友可以參考下
    2016-06-06
  • 輕松學(xué)習(xí)C#的方法

    輕松學(xué)習(xí)C#的方法

    輕松學(xué)習(xí)C#的方法,對C#的方法感興趣的朋友可以參考本篇文章,幫助大家更靈活的運用C#的方法
    2015-11-11
  • 基于XSLT調(diào)試的相關(guān)問題

    基于XSLT調(diào)試的相關(guān)問題

    本篇文章是對XSLT調(diào)試的相關(guān)問題進行了詳細的分析介紹,需要的朋友參考下
    2013-05-05

最新評論