用winform做程序的时候,我们一般都是在Program先启动登录窗体,然后登录成功后才创建主窗体,结果这就导致了登录窗体无法关闭

所以如果我们不在Program的程序入口先创建登录窗体的话就能完美实现登录成功后关闭登录窗体的功能了,直接贴代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms; namespace WindowsFormsApplication1
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm()); //程序启动于主窗体,而非登录窗体
}
}
}
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 WindowsFormsApplication1
{
public partial class LoginForm : Form
{
public MainForm mainForm; //获得主窗体引用,可以更新主窗体的登录标志
public LoginForm()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "admin")
{
mainForm.isLogin = true;
this.Close(); //登陆成功则关闭登录窗体
}
else
{
MessageBox.Show("密码错误!");
}
}
}
}
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 WindowsFormsApplication1
{
public partial class MainForm : Form
{
public bool isLogin = false; //登录标志
public MainForm()
{
InitializeComponent();
} private void MainForm_Load(object sender, EventArgs e)
{
LoginForm lf = new LoginForm();
lf.mainForm = this;
lf.ShowDialog();
if (isLogin)
{
label1.Text = "load success!"; //原load事件要放到这里
}
else
{
this.Close();
}
}
}
}

winform程序登陆后关闭登录窗体的更多相关文章

  1. winform关闭登录窗体打开主窗体的方法

    实际使用 Program.cs代码 //声明一个线程 private static System.Threading.Mutex mutex; /// <summary> /// 应用程序 ...

  2. WPF:验证登录后关闭登录窗口,显示主窗口的解决方法

    http://www.27ba.com/post/145.html WPF:验证登录后关闭登录窗口,显示主窗口的解决方法 最近想做一个基于Socket的通讯工具,想模仿QQ那样,需要先登录,登录成功后 ...

  3. C# 关闭登录窗体,显示主窗体

    首先在programm.cs里设置登录窗体显示 static class Program    {        /// <summary>        /// The main ent ...

  4. .NET混合开发解决方案15 WebView2控件集成到WinForm程序编译后的文件及结构说明

    系列目录     [已更新最新开发文章,点击查看详细] WebView2控件应用详解系列博客 .NET桌面程序集成Web网页开发的十种解决方案 .NET混合开发解决方案1 WebView2简介 .NE ...

  5. winform程序中为无边框窗体手动添加窗体拖动代码

            Point oldMousePoint;//记录开始移动窗口前鼠标点下箭头的位置        Point oldFormPoint;//记录开始移动窗口前窗体位置        // ...

  6. Winform程序拖拽文件到窗体

    1:首先需要将接收拖拽的窗体属性AllowDrop设置为True. 2:编写窗体拖拽进入(DragEnter)和拖拽完成(DragDrop)事件. private void FrmCode_DragE ...

  7. Identity Server 4登陆后返回登录前页面

  8. winform程序公布后,client下载报错“您的 Web 浏览器设置不同意执行未签名的应用程序”

    如题 在winserver2008服务器上操作会报错.解决的方法: IE→Internet选项→安全→可信网站,加入信任公布的IP地址

  9. WinForm 之 程序启动不显示主窗体

    在 WinForm 程序启动时,不显示主窗体的实现方法主要有以下5种,第五种最简单,而且效果也不错,第四种方法也值得推荐. 实例代码如下: //隐藏窗体的方法1/5:不指定任何窗体为主窗体 //注意: ...

随机推荐

  1. Django版本更新(升级)到指定版本的命令

  2. 四、bootstrap-Table

    一.bootstrap-Table基础表格 <!DOCTYPE html> <html lang="en"> <head> <meta c ...

  3. eclipse调试代码无法查看jdk变量解决方法

    1.无法查看jdk变量原因 oracle在公司在编译jdk的时候,把debug给关闭了,现在需要我们自己重新打包编译一次 2.eclipse创建一个普通java项目,取名叫jdk 3.导入jdk源码, ...

  4. PHP- 搜索插入位置

    给定一个排序数组和一个目标值,在数组中找到目标值,并返回其索引.如果目标值不存在于数组中,返回它将会被按顺序插入的位置. 你可以假设数组中无重复元素. 示例 1: 输入: [1,3,5,6], 5输出 ...

  5. 一个故事讲懂vue父子组件传值

    作者:李佳明同学链接:https://www.jianshu.com/p/2272b6ca0f0c 一个故事讲懂vue父子组件传值 讲故事前先讲代码 父组件向子组件传值 父组件数据传递给子组件可以通过 ...

  6. 【leetcode】1003. Check If Word Is Valid After Substitutions

    题目如下: We are given that the string "abc" is valid. From any valid string V, we may split V ...

  7. djangorestframework-jwt 分页器 三种

    数据准备 # models class Teacher(models.Model): name = models.CharField(max_length=32) salary = models.De ...

  8. dp的刷表法和填表法

    dp的刷表法和填表法 参考: 动态规划刷表法 - acmer_xue的博客 - CSDN博客http://blog.csdn.net/qq_30241305/article/details/52198 ...

  9. 队列Queue--数组实现

    队列是一种特殊的线性表,特殊之处在于它只允许在表的前端(front)进行删除操作,而在表的后端(rear)进行插入操作,和栈一样,队列是一种操作受限制的线性表.进行插入操作的端称为队尾,进行删除操作的 ...

  10. centos 安装 Lamp(Linux + Apache + PHP) 并安装 phpmyadmin

    来源:http://www.laozhe.net/302.html 一般情况下,安装的都是最新的正式版,除非你有特殊需求,要安装指定的版本,本文暂不讨论.从最基础的开始,一点点完成一个可用的 Linu ...