winform程序登陆后关闭登录窗体
用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程序登陆后关闭登录窗体的更多相关文章
- winform关闭登录窗体打开主窗体的方法
实际使用 Program.cs代码 //声明一个线程 private static System.Threading.Mutex mutex; /// <summary> /// 应用程序 ...
- WPF:验证登录后关闭登录窗口,显示主窗口的解决方法
http://www.27ba.com/post/145.html WPF:验证登录后关闭登录窗口,显示主窗口的解决方法 最近想做一个基于Socket的通讯工具,想模仿QQ那样,需要先登录,登录成功后 ...
- C# 关闭登录窗体,显示主窗体
首先在programm.cs里设置登录窗体显示 static class Program { /// <summary> /// The main ent ...
- .NET混合开发解决方案15 WebView2控件集成到WinForm程序编译后的文件及结构说明
系列目录 [已更新最新开发文章,点击查看详细] WebView2控件应用详解系列博客 .NET桌面程序集成Web网页开发的十种解决方案 .NET混合开发解决方案1 WebView2简介 .NE ...
- winform程序中为无边框窗体手动添加窗体拖动代码
Point oldMousePoint;//记录开始移动窗口前鼠标点下箭头的位置 Point oldFormPoint;//记录开始移动窗口前窗体位置 // ...
- Winform程序拖拽文件到窗体
1:首先需要将接收拖拽的窗体属性AllowDrop设置为True. 2:编写窗体拖拽进入(DragEnter)和拖拽完成(DragDrop)事件. private void FrmCode_DragE ...
- Identity Server 4登陆后返回登录前页面
- winform程序公布后,client下载报错“您的 Web 浏览器设置不同意执行未签名的应用程序”
如题 在winserver2008服务器上操作会报错.解决的方法: IE→Internet选项→安全→可信网站,加入信任公布的IP地址
- WinForm 之 程序启动不显示主窗体
在 WinForm 程序启动时,不显示主窗体的实现方法主要有以下5种,第五种最简单,而且效果也不错,第四种方法也值得推荐. 实例代码如下: //隐藏窗体的方法1/5:不指定任何窗体为主窗体 //注意: ...
随机推荐
- 11G利用隐含参数,修改用户名
步骤概述: 1. 停库,修改隐含参数_enable_rename_user 为true 2. 以 restrict方式启动数据库 3. alter user aaaa rename to ...
- jQuery HTML-删除元素
html <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <ti ...
- python plotly 使用教程
1.plotly介绍 lotly的Python图形库使互动的出版质量图表成为在线. 如何制作线图,散点图,面积图,条形图,误差线,箱形图,直方图,热图,子图,多轴,极坐标图和气泡图的示例. 推荐最好使 ...
- 给元素绑定 class
<div id="app04"> <label v-bind:class="{'Class1':Class1}">sasjadjagd& ...
- ELK Stack 7.1.1之集群搭建
一. 环境准备:3台Linux服务器,系统为CentOS 7.5 角色划分:3台机器全部安装jdk1.8,全部安装elasticsearch (后续都简称为es集群) 主节点上需要安装kibana与l ...
- springcloud的config
CONFIG服务端 加入依赖: <dependency> <groupId>org.springframework.cloud</groupId> <arti ...
- eureka学习(二)
eureka服务端创建好后,现在我们让eureka客户端(也就是服务提供者)注册到eureka上去. 首先加入依赖包: <!--将微服务provider注册到eureka--> <d ...
- Delphi 正则表达式之TPerlRegEx
官方网站: http://www.regular-expressions.info/delphi.html 直接下载: http://www.regular-expressions.info/down ...
- cs224d 作业 problem set1 (二) 简单的情感分析
使用在上一篇博客中训练好的wordvector 在这一节进行情感分析. 因为在上一节中得到的是一个词就是一个向量 所以一句话便是一个矩阵,矩阵的每一列表示一个词向量 情感分析的前提是已知一句话是 (超 ...
- 关于jsp:include 动态引入的值传递问题(数据共享问题)
<jsp:include page="search.jsp" flush="true"> <jsp:param name="gh&q ...