c # Form Learning

Recently, I began to learn the form of c #. Form is not a front-end. It's a bit like Dreamweaver and Frontpage. Similarly, there are designers and codes. Generally, as long as you operate in the designer, the corresponding codes will be generated automatically in the code interface.
At present, we have learned the events of buttons, radio boxes, check boxes, text boxes, panels and mouse keyboards in the form. It's interesting to see that the design interface drags the required objects in and can change their attributes in the attributes. Name and Text, which correspond to the object name, are used when calling the object in the code. Text is the content displayed, such as the common confirmation button Text, which is "OK".
Using the panel, you can make a virtual keyboard and enter the password. In fact, the label is set on the key position of the picture, the label is set to be transparent, then the code is written in the tag event MouseClick, and the mouse clicks the corresponding need. There are many events, such as MouseClick,MouseDown,MouseUp,MouseMove and so on. They are mouse click, press the mouse, release the mouse, move the mouse. After each event, code can be set to give him the corresponding response to the operation. It is very interesting to have a dialog box and perform different operations on an interface.
Here's the panel code for the virtual keyboard
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

    private void Label1_Click(object sender, EventArgs e)
    {
        displaytextBox.Text += "1";
    }

    private void Label2_Click(object sender, EventArgs e)
    {
        displaytextBox.Text += "2";
    }

    private void Label3_Click(object sender, EventArgs e)
    {
        displaytextBox.Text += "3";
    }

    private void Label4_Click(object sender, EventArgs e)
    {
        displaytextBox.Text += "4";
    }

    private void Label5_Click(object sender, EventArgs e)
    {
        displaytextBox.Text += "5";
    }

    private void Label6_Click(object sender, EventArgs e)
    {
        displaytextBox.Text += "6";
    }

   

    private void Label7_Click(object sender, EventArgs e)
    {
        displaytextBox.Text += "7"; 
    }

    private void Label8_Click(object sender, EventArgs e)
    {
        displaytextBox.Text += "8";
    }

    private void Label9_Click(object sender, EventArgs e)
    {
        displaytextBox.Text += "9";
    }

    private void Label10_Click(object sender, EventArgs e)
    {
        displaytextBox.Text += "0";
    }
    private void Backspace_Click(object sender, EventArgs e)
    {
        displaytextBox.Text = displaytextBox.Text.Substring(0, displaytextBox.Text.Length - 1);//The Substring() function selects from the first letter to the last - 1 letter, which is to delete the last letter.
    }

    private void Okbutton_Click(object sender, EventArgs e)
    {
        if (displaytextBox.Text == "123") MessageBox.Show("Password correct");
        else MessageBox.Show("Password error");
    }
}

Posted by mostwantedunm on Tue, 01 Oct 2019 17:35:16 -0700