大家一般常用的隐藏大概是hide
但是对与登录来说应该在主窗体之前验证,登录之后直接关闭不该隐藏。
要在main函数中运行主窗体之前验证,验证后关闭登录
Program.cs文件
using DataSync.Login;
namespace DataSync
{
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
ApplicationConfiguration.Initialize();
FormLogin login = new FormLogin();
DialogResult dialogResult = login.ShowDialog();
if (dialogResult == DialogResult.OK)
{
Application.Run(new FormMain());
}
}
}
}
登录窗体中验证账户密码
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 DataSync.Login
{
public partial class FormLogin : Form
{
public FormLogin()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (true)
{//如果密码正确返回ok
DialogResult = DialogResult.OK;
}
}
}
}
效果