Windows -Formulare C#: Problem mit Registrierungssystem, Formulare, ich weiß nicht, wie ich das Formular schließen und zC#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Windows -Formulare C#: Problem mit Registrierungssystem, Formulare, ich weiß nicht, wie ich das Formular schließen und z

Post by Anonymous »

Ich habe ein Problem in Bezug auf das Anmelde- und Passwortsystem. Ich habe kürzlich angefangen, mit C#zu arbeiten, und als Schüler muss ich ein Passwort- und Anmeldesystem schreiben, mit dem der Benutzer das Formular beenden kann, wenn er auf die Taste der Exit klickt, auch wenn die Felder leer sind.
Wenn ich jedoch die Taste der Beendigung drücke, ist die < /p>

Code: Select all

private void button1_Click(object sender, EventArgs e)
< /code>
Ereignishandler wird ausgelöst. Wenn ich das richtige oder falsche Passwort eingehe, funktioniert alles wie erwartet, aber sobald ich auf die Schaltfläche "Kennwort" klicke, funktioniert das Kennwortsystem nicht mehr. < /P>
Was könnte dies verursachen und wie kann ich? es lösen? Bitte helfen Sie < /p>
using System;
using System.Windows.Forms;

namespace TVCourseWork
{
public partial class Login : Form
{
private bool isClosing = false;
private bool IsLoggedIn = false;
private string correctUsername = "admin";
private string correctPassword = "1234";
TV mainForm = new TV();

public Login()
{
InitializeComponent();
this.FormClosing += new FormClosingEventHandler(Form1_FormClosing);
}

private void button2_Click(object sender, EventArgs e)
{
textBox1.Clear();
textBox2.Clear();
}

private void button1_Click(object sender, EventArgs e)
{
if (isClosing || IsLoggedIn)
return;

if (textBox1.Text == correctUsername && textBox2.Text == correctPassword)
{
IsLoggedIn = true;
MessageBox.Show("Вход выполнен успешно!", "Доступ разрешен", MessageBoxButtons.OK, MessageBoxIcon.Information);
AdminPanel adminPanel = new AdminPanel();
this.Hide();
adminPanel.ShowDialog();
this.Show();
}
else
{
MessageBox.Show("Неверный логин или пароль!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (!isClosing && !IsLoggedIn)
{
var result = MessageBox.Show("Вы уверены, что хотите выйти без входа?", "Подтверждение", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

if (result == DialogResult.Yes)
{
isClosing = true;
Application.Exit();
Application.Run(mainForm);
}
else
{
e.Cancel = true;
}
}
else if (IsLoggedIn)
{
isClosing = true;
Application.Exit();
Application.Run();
}
}
}
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post