C#菜单栏问题 [英] C# Menu Bar Issue
本文介绍了C#菜单栏问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我在Access 2007中使用C#2008.我在MDI上使用MDI,现在添加了一个菜单,因为Menu启用了Login MenuItem,并且在加载表单时禁用了其他菜单项.现在,如果登录成功,我将尝试实现此功能,然后其他菜单项将自动启用.我尝试了很多技巧,但无法从登录表单"访问菜单项.我在这里尝试的是代码-
Hi
I am using C# 2008 with Access 2007. I am using MDI on MDI a added a menu now that Menu have a Login MenuItem which is enable and other menu items are disabled at form load. Now I am try to implement this if login is successful then other menu items will be enabled automatically. I tried lots of technique but I can''t able to access Menu Items from Login Form. What I tried here is the code -
namespace EzBuddy
{
public partial class UserLoginForm : Form
{
//public NewUser nuser1;
private OleDbDataReader aReader;
private OleDbCommand aCommand;
private OleDbConnection aConnection;
public int login_flag = 0;
public UserLoginForm()
{
InitializeComponent();
}
public void menuEnable()
{
}
public void login_code()
{
int x = LoginBox.TextLength;
if (x < 5 || LoginBox.Text.Equals(""))
{
MessageBox.Show("ID is of minimum 5 digits as your Permanent Emplolee code or 9 digits as your Temporary Employee code", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
LoginBox.Text = "";
PasswordBox.Text = "";
LoginBox.Focus();
}
try
{
database_Connection();
aReader = aCommand.ExecuteReader();
while (aReader.Read())
{
if (aReader.GetString(0).Equals(LoginBox.Text) && aReader.GetString(1).Equals(PasswordBox.Text))
{
login_flag = 1;
break;
}
else
{
login_flag = 0;
}
}
if (login_flag == 1)
{
MDIParentForm.loginToolStripMenuItem1.Enabled = false;
MDIParentForm.newToolStripMenuItem3.Enabled = true;
MDIParentForm.editToolStripMenuItem3.Enabled = true;
MDIParentForm.deleteToolStripMenuItem3.Enabled = true;
MDIParentForm.
MDIParentForm.searchToolStripMenuItem1.Enabled = true;
MDIParentForm.reportsToolStripMenuItem1.Enabled = true;
MDIParentForm.utilitiesToolStripMenuItem.Enabled =true;
this.Dispose();
}
else
{
LoginBox.Text = "";
PasswordBox.Text = "";
LoginBox.Focus();
loginMessage.Visible = true;
aReader.Close();
aConnection.Close();
}
}
catch (Exception ex)
{
Console.WriteLine("Error: {0}", ex.Message);
}
finally
{
aReader.Close();
aConnection.Close();
}
}
private void database_Connection()
{
try
{
aConnection.Open();
Console.WriteLine("This is the returned data from Login table");
}
catch (OleDbException e)
{
Console.WriteLine("Error: {0}", e.Errors[0].Message);
}
}
private void UserLoginForm_Load(object sender, EventArgs e)
{
aConnection = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\KVSoftware\\KVStudent\\KV1StudentInformation.mdb");
aCommand = new OleDbCommand("select * from Login", aConnection);
}
private void LoginButton_Click(object sender, EventArgs e)
{
login_code();
}
}
}
帮助我解决此问题
Help me to solve this problem
推荐答案
究竟会发生什么?菜单状态不变吗?
我想登录表单是模态的吗? (显示登录表单时无法操作主窗口)
暂时尝试以下操作:
- 主窗口打开登录表单
- 登录表单处理登录并将结果返回到主窗口
- 主窗口基于菜单禁用其菜单返回
What exactly happens? The menu state is unchanged?
I suppose the login form is modal? (main window cannot be operated while the login form is displayed)
Try this for now:
- Main window opens login form
- Login form processes login and returns the result to the main window
- Main window disables its menu based on the return
这篇关于C#菜单栏问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文