Forum > Coding >

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

Posts: 15

Threads: 9

Joined: Jan, 2022

Reputation: 0

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");

  • 1

Posts: 673

Threads: 30

Joined: Aug, 2020

Reputation: 6

Replied

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

  • 0

Posts: 1658

Threads: 10

Joined: Sep, 2020

Reputation: 59

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");
         }
  • 1

Discord : Doctor Doom#0550

Posts: 15

Threads: 9

Joined: Jan, 2022

Reputation: 0

Replied

@0x777_ ty it worked perfectly

  • 0

Posts: 0

Threads: 0

Joined: ?

Reputation:

Replied

wrong usage of !=

 

"==" means equals to

"!=" means does not equals to

  • 0

Users viewing this thread:

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