都是在一个form中,显示哪个,就把其他的不可见;
namespace book
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (textName.Text == "admin" && textPass.Text == "admin")
{
MessageBox.Show("登陆成功,欢迎使用记事本");
button3.Visible = true;
button4.Visible = true;
textBox1.Visible = true;
textName.Visible = false;
textPass.Visible = false;
textBox1.WordWrap = false;
}
else {
MessageBox.Show("登陆失败,请重新输入");
textPass.Clear();
textName.Clear();
textName.Focus();
}
}
private void button2_Click(object sender, EventArgs e)
{
textPass.Clear();
textName.Clear();
textName.Focus();
}
private void Form1_Load(object sender, EventArgs e)
{
button3.Visible = false;
button4.Visible = false;
textBox1.Visible = false;
textName.Visible = true;
textPass.Visible = true;
}
private void button3_Click(object sender, EventArgs e)
{
if (button3.Text == "自动换行")
{
textBox1.WordWrap = true;
button3.Text = "取消自动换行";
}
else if (button3.Text == "取消自动换行")
{
textBox1.WordWrap = false;
button3.Text = "自动换行";
}
}
private void button4_Click(object sender, EventArgs e)
{
FileStream wrifi = new FileStream(@"C:\Users\Administrator\Desktop\a.txt",FileMode.OpenOrCreate ,FileAccess .Write );
string str = textBox1.Text;
byte[] nbyte = Encoding.Default.GetBytes(str);
wrifi.Write(nbyte,0,nbyte.Length );
MessageBox.Show ("保存成功");
this.Close();
}
}
}