如何从子窗体访问MDI父窗体的控件(ToolStripStatusLabel) [英] How to access a control (ToolStripStatusLabel) of a MDI parent form from a child form

查看:71
本文介绍了如何从子窗体访问MDI父窗体的控件(ToolStripStatusLabel)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从子表单访问MDI父表单的控件(ToolStripStatusLabel)。任何人都可以建议我如何访问它?



提前谢谢。

I am trying to access a control (ToolStripStatusLabel) of a MDI parent form from a child form. Can anyone please suggest me how to do access it?

Thanks in advance.

推荐答案

首先你需要公开到ToolStripStatusLabel然后尝试这个:

First you need to make public to ToolStripStatusLabel then try this:
Form1 parent = (Form1)this.MdiParent;
            var v = parent.ToolStripStatusLabel ;


您好,

如果您从子表单访问Mdiparent中的控件,最好的答案,请参阅:



将此代码放入mdichild表单中:



步骤:

1.将StatusStrip类型转换为您的控件

2.投放MDI父表单。 />
3.假设你的statusstrip控件名是statusStrip1:



Hello,
The best answer if you were accessing the controls inside a Mdiparent from a child form, see this:

Put this code in your mdichild form:

Steps:
1. Cast the StatusStrip type into your control
2. Cast the MDI parent form.
3. Assuming your statusstrip control name is statusStrip1:

foreach (ToolStripItem item in ((StatusStrip)((Form)this.ParentForm).Controls["statusStrip1"]).Items)
    {
        if (item.Name =="toolStripStatusLabel1") // you can loop to controls that reside into it. using another iteration but since i have one toolstriplabel, i don't use the iteration here.
           item.Text = "Welcome";
    }





问候,

Kix46



Regards,
Kix46






MDI表格代码如下

Hi,

MDI form code is below
public partial class Form1 : Form
   {
       public Form1()
       {
           InitializeComponent();
       }

       private void btnOpen_Click(object sender, EventArgs e)
       {
           Form2 frm = new Form2(toolStripStatusLabel1);
           frm.MdiParent = this;
           frm.Show();
       }
   }



和子表格代码在下面




and the child form code is below

public partial class Form2 : Form
   {

       public Form2(ToolStripStatusLabel statusStripLabel)
       {
           InitializeComponent();
           statusStripLabel.BackColor = Color.Black;

       }
   }





问候,



Regards,


这篇关于如何从子窗体访问MDI父窗体的控件(ToolStripStatusLabel)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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