我有登录表单和主表单,登录是用户时如何使按钮启用= false? [英] I have login form and main form , how I make button enable = false when the login is user?
问题描述
form1是loginform,而form2有按钮我想让这个按钮启用false ...
这是登录表格中的代码: -
s =从User_name ='+ txt_UserName.Text +'和Password ='+ txt_Password.Text +'和Role ='User'的用户中选择Role_id;
sdAdapter = new SqlDataAdapter(s,con);
dt = new DataTable();
sdAdapter.Fill(dt);
if(dt.Rows.Count == 1)
{
string s2 =insert into LoginAndOutDate(user_name,Login_Date);
s2 = s2 +values(@ user_name,CURRENT_TIMESTAMP);
if(con.State == ConnectionState.Closed)
con.Open();
使用(sCommand = new SqlCommand(s2,con))
{
sCommand.Parameters.AddWithValue(@ user_name,txt_UserName.Text);
sCommand.ExecuteNonQuery();
}
if(con.State == ConnectionState.Open)
con.Close();
这个。隐藏();
FRM_Main frm = new FRM_Main(txt_UserName.Text);
frm.RefToFormLogin = this;
frm.Show() ;
txt_Password.Clear();
我尝试过:
如何使用另一种形式启用按钮= false
form1 is loginform, and form2 has button i want make this button is enabled false...
This is Code in login form:-
s = "select Role_id from Users where User_name = '" + txt_UserName.Text + "' and Password = '" + txt_Password.Text + "' and Role = 'User' ";
sdAdapter = new SqlDataAdapter(s, con);
dt = new DataTable();
sdAdapter.Fill(dt);
if (dt.Rows.Count == 1)
{
string s2 = " insert into LoginAndOutDate(user_name, Login_Date) ";
s2 = s2 + " values(@user_name, CURRENT_TIMESTAMP) ";
if (con.State == ConnectionState.Closed)
con.Open();
using (sCommand = new SqlCommand(s2, con))
{
sCommand.Parameters.AddWithValue("@user_name", txt_UserName.Text);
sCommand.ExecuteNonQuery();
}
if (con.State == ConnectionState.Open)
con.Close();
this.Hide();
FRM_Main frm = new FRM_Main(txt_UserName.Text);
frm.RefToFormLogin = this;
frm.Show();
txt_Password.Clear();
What I have tried:
How i make button is enabled = false from another form
推荐答案
最简单的方法是在表单构造函数中添加第二个参数:
Easiest way is to add a second parameter to your form constructor:
public FRM_Main(string userName, bool enableMyButton)
{
InitializeComponent();
...
myButton.Enabled = enableMyButton;
}
然后在构造表单实例时传递适当的值。
And then pass the appropriate value when you construct the form instance.
这篇关于我有登录表单和主表单,登录是用户时如何使按钮启用= false?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!