Eiweisshakee
New member
- Joined
- Nov 22, 2022
- Messages
- 3
- Programming Experience
- 1-3
Hello, I'm currently trying something out with c Sharp and wanted to see if I could manage a login with multiple forms. Didn't work out so well. Attached is the source code, the point is that if you have successfully logged in, you cannot switch the forms because the bool is apparently read incorrectly. Would be nice if you can give me tips in which direction I could try it
Login class:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Koloniya_ControlPanel
{
public partial class Login : Form
{
bool loggedIn;
bool isAdmin;
bool isMod;
public Login()
{
InitializeComponent();
textBox2.PasswordChar = '\u25CF';
}
public bool Enabled
{
get
{
return this.loggedIn;
}
set
{
this.loggedIn = value;
}
}
private void label1_Click(object sender, EventArgs e)
{
}
public void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "Eiweisshakee" && textBox2.Text == "87237597485" || textBox1.Text == "Schokoshakee" && textBox2.Text == "77899652254" || textBox1.Text == "Cholian" && textBox2.Text == "36577546465")
{
this.Enabled = true;
Console.Out.WriteLine(loggedIn);
isAdmin = true;
isMod = true;
MessageBox.Show("Erfolgreich eingeloggt!");
}
else if(textBox1.Text == "Seylooo" && textBox2.Text == "82935976898" || textBox1.Text == "Snackii" && textBox2.Text == "46562835282" || textBox1.Text == "dia78" && textBox2.Text == "99885962382")
{
loggedIn = true;
isAdmin = false;
isMod = true;
MessageBox.Show("Erfolgreich eingeloggt!");
}
else
{
MessageBox.Show("Falsche Accountdaten!");
}
}
}
}
Main class:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Koloniya_ControlPanel;
namespace Koloniya_ControlPanel
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void loadForm(object Form)
{
if (this.mainpanel.Controls.Count > 0)
this.mainpanel.Controls.RemoveAt(0);
Form f = Form as Form;
f.TopLevel = false;
f.Dock = DockStyle.Fill;
this.mainpanel.Controls.Add(f);
this.mainpanel.Tag = f;
f.Show();
}
private void button1_Click(object sender, EventArgs e)
{
loadForm(new Login());
}
private void button2_Click(object sender, EventArgs e)
{
Login f = new Login();
if (f.Enabled.Equals(true))
{
loadForm(new Spielerabfrage());
}
else
{
MessageBox.Show("Nicht eingeloggt!");
}
}
}
}
Last edited: