单击“X”时我的程序没有退出,所以当我查找它时,我得到了这个代码。
protected override void OnFormClosing(FormClosingEventArgs e)
{
Application.Exit();
}
但这会干扰该this.Close()
方法。
有没有办法在单击“X”而不是在表单实际关闭时使用此代码?这似乎是唯一有问题的表格?
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 PassMan
{
public partial class Passwords : Form
{
String[,] UandS = { { "Russell", "Hickey" }, { "Junior", "Russ" } };
public Passwords()
{
InitializeComponent();
for (int i = 0; i < UandS.Length / 2; i++)
{
for (int j = 0; j < 2; j++)
{
if (j % 2 == 0)
{
tbUsernames.Text = tbUsernames.Text + UandS[i, j] + "\r\n";
}
else
{
tbPasswords.Text = tbPasswords.Text + UandS[i, j] + "\r\n";
}
}
}
tbPasswords.PasswordChar = '*';
}
private void btnSH_Click(object sender, EventArgs e)
{
Properties.Settings.Default.Save();
if (btnSH.Text == "Show Passwords")
{
btnSH.Text = "Hide Passwords";
tbPasswords.PasswordChar = (char)0;
}
else
{
btnSH.Text = "Show Passwords";
tbPasswords.PasswordChar = '*';
}
}
private void btnClose_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void btnLogin_Click(object sender, EventArgs e)
{
fLogin main = new fLogin();
main.Show();
this.Close();
}
protected override void OnFormClosing(FormClosingEventArgs e)
{
//Application.Exit();
}
}
}