从子窗体更改父窗体的标签文本 [英] change label text of parent form from child form

查看:45
本文介绍了从子窗体更改父窗体的标签文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
从子表单访问父表单上的控件

我有父表单form1和子表单test1,我想从父表单的子表单中更改父表单的标签文本,但我有showresult()方法

I have parent form form1 and child form test1 i want to change label text of parent form from child form in my parent form i have method to showresult()

public void ShowResult(){label1.Text ="hello";}

我想在按钮单击事件上将 label.Text ="Bye"; 更改为我的子表单test1.请提出任何建议.

I want to change label.Text="Bye"; form my child form test1 on button click event. Please give any suggestions.

推荐答案

在调用子表单时,请像这样设置子表单对象的 Parent 属性.

when calling the child form, set the Parent property of child form object like this..

Test1Form test1 = new Test1Form();
test1.Show(this);

在您的父表单上,使标签文本的属性像..

On your parent form, make the property of your label text like as..

public string LabelText
{
  get
  {
    return  Label1.Text;
  }
  set
  {
    Label1.Text = value;
  }
}

从您的子表单中,您可以获取类似的标签文本.

From your child form you can get the label text like that..

((Form1)this.Owner).LabelText = "Your Text";

这篇关于从子窗体更改父窗体的标签文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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