Click here to Skip to main content
15,850,685 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

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

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form a = new Form2();
            string Username = "Username";
            string Password = "Password";
            if ((textBox1.Text == Username) & (textBox2.Text == Password)) ;
            a.ShowDialog(); 
           
            else
            {
            
                a.Close();
            }
        }
    }
}
Posted
Updated 18-Jun-19 4:59am
v2
Comments
Sergey Alexandrovich Kryukov 21-Jan-13 18:03pm    
Do you think if you ask such questions on all difficulties like that it might help your to learn how to program? No way. It will only delay it. All you need is get to work and use your brain.
—SA

you have terminated the if statement with this ";"

replace this
if ((textBox1.Text == Username) & (textBox2.Text == Password)) ;

with this
if ((textBox1.Text == Username) & (textBox2.Text == Password))
 
Share this answer
 
Comments
ahmed youness11 21-Jan-13 18:18pm    
THXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX VERY MUCH
[no name] 18-Jun-19 10:44am    
works well, thnx
Must be: if (/* ... */) {/* ... */} else {/* ... */}.
—SA
 
Share this answer
 
Comments
Jibesh 21-Jan-13 18:05pm    
You gone tougher this time... asking the OP to think about his mistakes rather a direct solution ;)
Sergey Alexandrovich Kryukov 21-Jan-13 18:29pm    
Thank you. If not thinking, why doing any programming at all?
—SA
Jibesh 21-Jan-13 18:29pm    
:) :)
Andreas Gieriet 21-Jan-13 19:17pm    
My 5 for the answer and the comment to the question.
I did not try the code but I bet there was a decent error message on the semi-colon after the if condition. Said that, I know that sometimes one does not see the obvious until someone else points to it ;-)
On the other hand, the OP pasting the code without a comment looks a bit cheap.
Cheers
Andi
Sergey Alexandrovich Kryukov 21-Jan-13 19:30pm    
Thank you, Andi.

Semi-column after condition is legitimate; it means "empty statement" (and causes warning, as far as I remember), but the code below breaks the balance of the construct...
—SA
HI,

Please check with your coding

C#
if ((textBox1.Text == Username) & (textBox2.Text == Password)) ;



you can't use the semicolon ";" at the end of the if condition.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900