I am making a program with a login system, but I cannot get the login part to work.
This is what I tried:
But it didnt work.Code: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 Login_Click(object sender, EventArgs e) { if (txtuser = "magic" & txtpass = "magic" Form2.ShowDialog; else MessageBox.Show("Login failed"); } } }
How can I make a login system that works?
Well, for the reason this particular code isn't working, could be to do with a missing bracket.
Try this.
Code: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 Login_Click(object sender, EventArgs e) { if (txtuser = "magic" & txtpass = "magic") Form2.ShowDialog; else MessageBox.Show("Login failed"); } } }
Cool!
That got rid of one error
It still as this error: Error 1 Operator '&' cannot be applied to operands of type 'string' and 'System.Windows.Forms.TextBox' C:\Users\McKinlay\Documents\Visual Studio 2008\Projects\WindowsFormsApplication1\WindowsForm sApplication1\Form1.cs 21 27 WindowsFormsApplication1
and this error:Error 2 Only assignment, call, increment, decrement, and new object expressions can be used as a statement C:\Users\McKinlay\Documents\Visual Studio 2008\Projects\WindowsFormsApplication1\WindowsForm sApplication1\Form1.cs 21 56 WindowsFormsApplication1
You can't use & to compare two booleans you need to use &&.
You also need to create an instance of Form2 before you actually call one of its methods. I also added brackets to make things easier.
And also when your comparing things you need to use double equal signs.
Your code should look like this.
Code: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 Login_Click(object sender, EventArgs e) { if (txtuser == "magic" && txtpass == "magic") { Form2 f2 = new Form2(); f2.ShowDialog(); } else { MessageBox.Show("Login failed"); } } }
Last edited by QuackWare; 01-31-2010 at 02:34 PM.
Cool, I figured out how to create a login system!
Thanks guys!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks