以一种形式从另一种形式访问ToolStrips [英] Accessing ToolStrips in one form from another

查看:120
本文介绍了以一种形式从另一种形式访问ToolStrips的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个主要表单,其中有一个带有工具条的menustrip,表示登录,管理员和用户。我已经禁用了管理员和用户的工具条。因为当我登录并且loginform的用户名没有说admin时,应该启用用户工具条。但我遇到的问题是登录按钮后面的代码似乎没有启用任何一个工具条。

登录工具栏弹出一个表单,其中包含用户名和密码以及loginBtn



  if (userID.Equals(txtUserID_.Text)|| password .Equals(txtPassword_.Text))
{
user = txtUserID_.Text;
MessageBox.Show( 用户身份和密码验证);
//
if (txtUserID_.Text!= Admin
{
mnFrm.adminTS.Enabled = true ;
}



工具条中的代码是

  private   void  adminToolStripMenuItem_Click( object  sender,EventArgs e)
{
adminTSMenuItem.Enabled = false ;
}
private void faultToolStripMenuItem_Click( object sender,EventArgs e)
{
faultTSMenuItem.Enabled = false ;
}

解决方案

参考这篇文章它会对你有所帮助。

研究它为您改变代码。

http://www.c-sharpcorner.com/uploadfile/mma1979/how-to-access-mdiparent-controls-from-child-forms/ [ ^ ]

好吧所以我自己通过在父表单中为禁用控件创建公共方法然后在子表单中调用它来解决它。

//这在父表格

  //  禁用错误/抱怨和管理员 
public void DisableControls()
{
adminTSMenuItem.Enabled = false ;
// faultTSMenuItem.Enabled = false;
}

// 启用错误/抱怨和管理
public void EnableControls()
{
adminTSMenuItem.Enabled = true ;
faultTSMenuItem.Enabled = true ;
}





//登录儿童表格

 f(txtUserID_.Text!=  管理员
{
MessageBox.Show( 用户身份和密码验证);
((Main) this .MdiParent).DisableControls();
}
其他
{
((主要) .MdiParent).EnableControls();
}
.Close();





谢谢大家帮帮我。


I Have a main form that has a menustrip with toolstrips that say login, admin and user. and I have disabled the toolstrips that say admin and user. because when i log in and the username for the loginform does not say admin only the user toolstrip should be enabled. but the problem I am having is that the code behind the login button does not seem to enable either of the toolstrips.
the login toolstrip pops up a form with the fields namely Username and password and a loginBtn

if (userID.Equals(txtUserID_.Text) || password.Equals(txtPassword_.Text))
                    {
                        user = txtUserID_.Text;
                        MessageBox.Show("User Identity and Password Verified");
                        //
                        if (txtUserID_.Text != "Admin")
                        {
                            mnFrm.adminTS.Enabled = true;
                        }


And the code in the toolstrips are

        private void adminToolStripMenuItem_Click(object sender, EventArgs e)
      {
          adminTSMenuItem.Enabled = false;
      }
private void faultToolStripMenuItem_Click(object sender, EventArgs e)
      {
          faultTSMenuItem.Enabled = false;
      }

解决方案

Refer this article it will help you.
Study it and change for you code.
http://www.c-sharpcorner.com/uploadfile/mma1979/how-to-access-mdiparent-controls-from-child-forms/[^]


okay so i solved it myself by creating a public method for the disable controls in the parent form and then calling in it in the child form.
//this in the parent form

//disables fault/complains and admin
       public void DisableControls()
       {
           adminTSMenuItem.Enabled = false;
           //faultTSMenuItem.Enabled = false;
       }

       //enables fault/complains and admin
       public void EnableControls()
       {
           adminTSMenuItem.Enabled = true;
           faultTSMenuItem.Enabled = true;
       }



//login child form

f (txtUserID_.Text != "Admin")
                        {
                            MessageBox.Show("User Identity and Password Verified");
                            ((Main)this.MdiParent).DisableControls();
                        }
                        else
                        {
                            ((Main)this.MdiParent).EnableControls();
                        }
                        this.Close();



Thanks Guys help me alot.


这篇关于以一种形式从另一种形式访问ToolStrips的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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