Categories > Coding > C# >

How to make textbox in a kind of key system on a windows form app


Posts: 13

Threads: 8

Joined: Jan, 2022

Reputation: 0

  • 1

Posted

this is what i got so far but it just open the form even tho i didnt type anything

 

private void button1_Click(object sender, EventArgs e)

        {

            if (textBox1.Text != "coco")

            {

                Form1 form = new Form1();

                form.Show();

                this.Hide();

            }

            else

                MessageBox.Show("Wrong key");

MaximusExploit

Maximus

Posts: 927

Threads: 34

Joined: Aug, 2020

Reputation: 18

  • 0

Replied

you're using the not equals operator ( != )

0x777_

Baba Yaga

noticed

Posts: 1969

Threads: 12

Joined: Sep, 2020

Reputation: 43

  • 1

Replied

Just do

private void button1_Click(object sender, EventArgs e)

        {

            if (textBox1.Text == "coco")
            {

                new Form1().Show();
                this.Hide();
                return;
            }

            MessageBox.Show("Wrong key");
         }

Posts: 13

Threads: 8

Joined: Jan, 2022

Reputation: 0

  • 0

Replied

@0x777_ ty it worked perfectly

SirWeeb

Novaline Owner

moderator

Posts: 990

Threads: 29

Joined: Jul, 2021

Reputation: 39

  • 0

Replied

wrong usage of !=

 

"==" means equals to

"!=" means does not equals to



Users viewing this thread:


( Members: 0, Guests: 1, Total: 1 )