SoFunction
Updated on 2025-03-08

C# implements QQ chat window

This article shares the specific code of C# to implement QQ chat window for your reference. The specific content is as follows

analyze

  • Two TextBoxes are required, one for displaying messages and one for editing messages
  • Four buttons are required to control the closing of the program, clear the edited message, send the message, and shake it

principle

1. Edit and send messages in TextBox2. While displaying the sent messages in TextBox1, clear the messages in TextBox2.
2. The first message sent by TextBox1 is saved and displayed first. When sending the second message, the previous message of TextBox1 is printed out first and then the second message is displayed.
3. Jitter principle: change the left and top of the window (considering the coordinate origin around the upper left corner of the form) and add Thread thread and for loop to achieve window jitter effect

Important attributes used in the program

ReadOnly property: Set text to read-only (true)=true;

TabIndex attribute: Set where the cursor appears by default (0)=0;

Multiline property: Set text box to enter multiple lines=true;

Datetime: Get the current time

"\r\n" line break

AcceptButton property: Get or set the button on the form that is clicked when the user presses the Enter key = button2;

Thread class: Create and control threads(10);//Set the stay time after the previous step is completedYou also need to create a namespaceusing ;

Trim method:()=="")//Trim: Remove the whitespace characters before and after the current textBox2 object position

The specific code is as follows:

using System;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
using ;//Set multi-threading
namespace Test_QQ_chat_windows
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        { 
            //Click the chat window to center             =  / 2 -  / 2;
             =  / 2 -  / 2;
            //Name of the chat window             = "Chamber with Know";
             = ("../../img/");//Set the form background image             = ;//Set the form background image stretch            //textBox1 setting read-only             = true;
            //Set the send button to trigger it with the Enter key             = button2;
             = 0.8;//Set the form transparency to 0.2             = ;
             = ;
        }

        private void button1_Click(object sender, EventArgs e)
        {
             = ;//Set the background color of the form             += "Late night dining room(36522224)" +  + "\r\n"+ "\r\n" + "You sent a window jitter" + "\r\n"+"\r\n";
             = "";//Set there is no content in textBox2 after sending content            //The window shakes            int x = ;
            int y = ;
            for (int i = 0; i <= 3; i++)//Set the number of jitters            {
                 = new Point(x - 3, y);
                (10);//Set the stay time after the previous step                 = new Point(x - 3, y - 3);
                (10);
                 = new Point(x, y - 3);
                (10);
                 = new Point(x + 3, y - 3);
                (10);
                 = new Point(x + 3, y);
                (10);
                 = new Point(x + 3, y + 3);
                (10);
                 = new Point(x, y + 3);
                (10);
                 = new Point(x - 3, y + 3);
                (10);
                 = new Point(x - 3, y);
                (10);
                 = new Point(x, y);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //Message sending            //Judge whether there is any content in textbox2            if ( == ""||()=="")//Trim: Remove the blank characters before and after the current textBox2 object position)            {
               ("The input cannot be null, please re-enter", "hint", , );
            }
            else
            {
                  += "Late night dining room(36522224)" +  + "\r\n" + "\r\n" +  + "\r\n"+ "\r\n";
                 = "";//Set there is no content in textBox2 after sending content            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            ();
        }

        private void button4_Click(object sender, EventArgs e)
        {
             = "";
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            //Set the start point at the last message            this. = this.;
            //Scroll to the last message            this.();
        }
    }
}

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.