从另一个窗体调用窗体控件。 [英] Calling a windows form controls from another windows form .

查看:103
本文介绍了从另一个窗体调用窗体控件。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello All

我是c#编码新手。

在我的项目中,我想自定义 frmAdminIndex 工具条菜单(项目可见性更改)。 frmAdminIndex通过使用放置在 frmDashBoard 中的Checkbox进行了cusytomom。附带代码



代码控制

 命名空间 InventoryMnt 
{
public 部分类< big> frmAdminIndex:表单< / big >
{
Sales2Method salesMethod = new Sales2Method();

public frmAdminIndex()
{
InitializeComponent();
}
public frmAdminIndex( string Emp1)
{
InitializeComponent();
Emp = Emp1;

}

public frmAdminIndex( string Emp1 , string pass)
{
InitializeComponent();
User = Emp1;
Pass = pass;
}

public void Control1()
{
.oldGoldToolStripMenuItem.Visible = false ;

}
public string Emp
{
set
{
< big> this.txtemp.Text = value ;
this .aDMINISTRATIONToolStripMenuItem.Visible = false ;
.reportsToolStripMenuItem.Visible = false ;
this .backUpToolStripMenuItem.Visible = false ;
this .accountsToolStripMenuItem.Visible = false ;

this .inventoryToolStripMenuItem1.Visible = true ;
.stockEntryToolStripMenuItem1.Visible = true ;
.stockReturnToolStripMenuItem1.Visible = true ;
.salesToolStripMenuItem1.Visible = true ; < / >

}
}





控制表格

 公开 部分 < big> frmDashBoard:表单< /   big  >  
{

public frmDashBoard()
{
InitializeComponent();
}

private void checkBox1_CheckedChanged( object sender,EventArgs e)
{
/// 在这里我必须输入代码来控制frmAdminIndex中的工具条项

}
}
}









Nidheesh

解决方案

< blockquote>最简单的方法是将控件公开(但不是最佳实践)。请参阅: http://msdn.microsoft.com/en-us/library/ms233630.aspx [ ^ ],此图片为找物业: http://brwiki.brulescorp.com/images/e/e7/CalendarProperties.JPG [ ^ ]。



然而,最好的方法是在表单中添加一些公共方法并在那里传递必要的信息。这样每种形式都可以处理它自己的东西,而且它们不会干涉。顺便提一下,如果你采用多线程解决方案,你也可以使用它。


Hello All
Am new in c# coding.
On my project i want to customize frmAdminIndex toolstrip menu (item visibility change) .The frmAdminIndex was cusytomized by using Checkbox placed in frmDashBoard.Both Code attached

Code to Control

namespace InventoryMnt
{
    public partial class<big> frmAdminIndex : Form</big>
    {
        Sales2Method salesMethod = new Sales2Method();

        public frmAdminIndex()
        {
            InitializeComponent();
        }
        public frmAdminIndex(string Emp1)
        {
            InitializeComponent();
            Emp = Emp1;

        }

        public frmAdminIndex(string Emp1, string pass)
        {
            InitializeComponent();
            User = Emp1;
            Pass = pass;
        }

        public void Control1()
        {
            this.oldGoldToolStripMenuItem.Visible = false;

        }
        public string Emp
        {
            set
            {
                <big>this.txtemp.Text = value;
                this.aDMINISTRATIONToolStripMenuItem.Visible = false;
                this.reportsToolStripMenuItem.Visible = false;
                this.backUpToolStripMenuItem.Visible = false;
                this.accountsToolStripMenuItem.Visible = false;
               
                this.inventoryToolStripMenuItem1.Visible = true;
                this.stockEntryToolStripMenuItem1.Visible = true;
                this.stockReturnToolStripMenuItem1.Visible = true;
                this.salesToolStripMenuItem1.Visible = true;</big>
               
            }
        }



Controlling Form

public partial class <big>frmDashBoard : Form</big>
    {

        public frmDashBoard()
        {
            InitializeComponent();
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            ///Here I have to type the code to control tool strip item in frmAdminIndex 

        }
    }
}





Nidheesh

解决方案

The simplest way is to make the control public (far not the best practice however). See: http://msdn.microsoft.com/en-us/library/ms233630.aspx[^], and this image to find the property: http://brwiki.brulescorp.com/images/e/e7/CalendarProperties.JPG[^].

The best approach however is to add some public methods to your form and pass the necessary information there. This way every form can deal wit it''s own stuff, and they don''t interfere. And by the way you can use this also if you step forward to a multithreaded solution.


这篇关于从另一个窗体调用窗体控件。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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