登陆显示主窗体 如题! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 登陆验证成功后,记录一个状态:Bool LoginState = true;记录后关闭登陆窗体 在Program.cs改为: LoginForm login= new LoginForm(); if(LoginState ) Application.Run(new MainForm()); 不好意思。没看清楚。 Form2 f = new Form2(); f.Show(); this.Hide();form2为你的主界面。this为你的登录窗口 楼上的朋友,Hide()了可是还是在运行啊,只是说看不到界面了而已!你一直用这种方法? 恩请问有什么好的方法吗?不是改动program文件 static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Form1 f1 = new Form1(); //登录窗体 f1.ShowDialog(); if (f1.y == true) //根据输入的打开窗体 根据不同权限进入窗体 { Application.Run(new FormAdmin("1")); } if (f1.x == true) { Application.Run(new FormAdmin()); } if (f1.z == true) { Application.Run(new FormAdmin(1)); } } public bool y = false; //登录窗体定义变量 public bool x = false; public bool z = false; public Form1() { InitializeComponent(); StartPosition = FormStartPosition.CenterScreen; } private void button1_Click(object sender, EventArgs e) { string a = this.textBox1.Text; string b = this.textBox2.Text; string c = this.comboBox1.Text; database db = new database(); string sql="select * from admin where entername='"+a+"'and userpassword='"+b+"' and userrole='"+c+"'"; SqlDataReader sqlrd=db.read(sql).ExecuteReader(); if (!sqlrd.Read()) { MessageBox.Show("用户名或密码或用户角色输入错误!"); this.textBox1.Text = ""; this.textBox2.Text = ""; } else if (c == "标准维护人") { x = true; this.Close(); } else if (c == "普通用户") { y = true; this.Close(); } else if (c == "标准发布人") { z = true; this.Close(); } } 我这个方法不用Hide()隐藏。修改program文件里面,手动打开登录窗体,然后根据登录窗体的值打开主窗体并关闭登录窗体!绝对好用。LZ给分吧 ?你这是什么问题?我告诉你我的方法。程序启动的时候 Application 里面new 的是一个登录窗体,登录后,再去new 主窗体…… 刚学c#来学习,不是不能关闭主窗体吗?我们教员教得一直是this.visible = false;这样的行不? 有谁能说一下使用hide()方法与操作program.cs文件那个占用内存小一点? 使用C#如何从指定服务器上下载指定文件到本地 急:远程获取服务器上web文件信息 跪求高人!关于多线程读写.txt文件问题! C#编译的可执行文件在别人的电脑上打不开为什么打不开 请问高手一个WEB无刷新问题ListBox的左右取值 C#如何产生随机数字的程序 如何设置资源管理器中详细列表中的属性列? 请问C#如何搜索KAD网络? “.csproj”文件怎么可不可以单独创建? 请教查询结果显示的问题!!!!(在线等待,小弟非常急) 怎样把IPAddress类型转换为string? 面试问题
在Program.cs改为:
LoginForm login= new LoginForm();
if(LoginState )
Application.Run(new MainForm());
Form2 f = new Form2();
f.Show();
this.Hide();
form2为你的主界面。this为你的登录窗口
你一直用这种方法?
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Form1 f1 = new Form1(); //登录窗体
f1.ShowDialog();
if (f1.y == true) //根据输入的打开窗体 根据不同权限进入窗体
{
Application.Run(new FormAdmin("1"));
}
if (f1.x == true)
{
Application.Run(new FormAdmin());
}
if (f1.z == true)
{
Application.Run(new FormAdmin(1));
}
}
public bool y = false; //登录窗体定义变量
public bool x = false;
public bool z = false;
public Form1()
{
InitializeComponent();
StartPosition = FormStartPosition.CenterScreen;
}
private void button1_Click(object sender, EventArgs e)
{
string a = this.textBox1.Text;
string b = this.textBox2.Text;
string c = this.comboBox1.Text;
database db = new database();
string sql="select * from admin where entername='"+a+"'and userpassword='"+b+"' and userrole='"+c+"'";
SqlDataReader sqlrd=db.read(sql).ExecuteReader();
if (!sqlrd.Read())
{
MessageBox.Show("用户名或密码或用户角色输入错误!");
this.textBox1.Text = "";
this.textBox2.Text = "";
}
else if (c == "标准维护人")
{
x = true;
this.Close();
}
else if (c == "普通用户")
{
y = true;
this.Close();
}
else if (c == "标准发布人")
{
z = true;
this.Close();
} }
来学习,不是不能关闭主窗体吗?我们教员教得一直是this.visible = false;
这样的行不?