登录后访问主窗体的menustrip [英] Access menustrip of main form after login

查看:74
本文介绍了登录后访问主窗体的menustrip的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Main_Form 退出后,我制作了menustrip启用属性 False 。之后我点击 Main_Form 的登录按钮打开 Login_Form

登录后我想制作menustrip启用属性 True 来自 Login_Form 。但是,无论如何都不会发生这种情况。



如果您帮助从另一个表单访问 Main_Form 控件的属性,我将非常感激没有声明控件公开



Main_Form中的代码:

< pre lang =c#> public Form_Main( bool login)
{
尝试
{

if (login == true
{
Library.Logout = false ;
Library.LoginSuccess_Again = false ;

foreach (ToolStripMenuItem item in menu_main.Items)
{
if (item.Name!= loginToolStripMenuItem
item.Enabled = true ;
if (item.Name == loginToolStripMenuItem
item.Enabled = false ;
}
}
}
catch (异常错误)
{
MessageBox.Show (err.Message);
}
}





Login_Form中的代码:

  if (IsLogin( this  .txtUsername.Text.ToString( ), .txtPassword.Text.ToString())==  true 
{
var obj = new Form_Main( true );
}





另一个尝试



Main_Form:

  public   void  test()
{
try
{
foreach (ToolStripMenuItem item in menu_main.Items)
{
if (item.Name!= loginToolStripMenuItem
item.Enabled = true ;
if (item.Name == loginToolStripMenuItem
item.Enabled = false ;
}
}
catch (异常错误)
{
MessageBox.Show(err.Message) ;
}
}





Login_Form:

  if (IsLogin( this  .txtUsername.Text.ToString(),  .txtPassword.Text.ToString())==  true 
{
Form_Main obj = new Form_Main();
obj.Test();
}





我的尝试:



首先我尝试过Constructor调用。

其次我通过在Login_Form中创建一个对象来调用Main_Form中存在的公共方法。

解决方案

不要。

相反,使用主表单处理的登录表单事件来获取主表单。

请参阅此处:在两种形式之间传递信息,第2部分:儿童到父母 [ ^ ]子是登录表单,父是主要形式。


After Logout from Main_Form I make menustrip Enable properties False. After than I clicked on Login button of the Main_Form to open Login_Form.
And after login I want to make menustrip Enable properties True from Login_Form. But, this not happening anyway.

I will be thankful if you help to access Main_Form control's properties from another Form without declare Controls public.

Code in Main_Form:

public Form_Main(bool login)
        {
            try
            {
                    
                if (login == true)
                {
                    Library.Logout = false;
                    Library.LoginSuccess_Again = false;

                    foreach (ToolStripMenuItem item in menu_main.Items)
                    {
                        if (item.Name != "loginToolStripMenuItem")
                            item.Enabled = true;
                        if (item.Name == "loginToolStripMenuItem")
                            item.Enabled = false;
                    }
                }
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message);
            }
        }



Code in Login_Form:

if (IsLogin(this.txtUsername.Text.ToString(), this.txtPassword.Text.ToString()) == true)
{
    var obj = new Form_Main(true);
}



Another tried

Main_Form:

public void test()
        {
            try
            {
                foreach (ToolStripMenuItem item in menu_main.Items)
                {
                    if (item.Name != "loginToolStripMenuItem")
                        item.Enabled = true;
                    if (item.Name == "loginToolStripMenuItem")
                        item.Enabled = false;
                }
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message);
            }
        }



Login_Form:

if (IsLogin(this.txtUsername.Text.ToString(), this.txtPassword.Text.ToString()) == true)
            {
Form_Main obj = new Form_Main();
obj.Test();
}



What I have tried:

First I have tried by Constructor calling.
Secondly I have call a public method which exist in Main_Form by making a object in Login_Form.

解决方案

Don't.
Instead, use an login form event which the main form handles to get teh main form to do that.
See here: Transferring information between two forms, Part 2: Child to Parent[^] The "child" is the Login form, the "parent" is the Main form.


这篇关于登录后访问主窗体的menustrip的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆