从另一个表单完全访问控件 [英] Fully access a control from another Form

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

问题描述

我有一个主 Windows 窗体 (From1),其中有一个 TextBox.我还创建了另一个 Windows 窗体 (FindReplaceForm),我将用它来实现查找和替换对话框的窗体.我需要从 FindReplaceForm 窗口完全访问我在 From1 中的文本框的所有属性和方法.

I have a main Windows Form (From1) which has a TextBox in it. I've also created another Windows Form (FindReplaceForm) which I'm going to use for implementing a form of find and replace dialog. I need to fully access all the properties and methods of my textbox in From1 from FindReplaceForm window.

虽然我将 TextBox 的 Modifiers 属性设置为 Public,但在 FindReplaceForm 窗口中我无法访问其中的文本.

Although I set the Modifiers property of my TextBox to Public, in FindReplaceForm window I can't access the text in it.

推荐答案

您可以使用以下方法访问孩子中的所有者表单:

You can access the the owner form in the child using:

((Form1)Owner).textBox1.Text = "blah";

假设您使用以下方法调用了子表单:

Assuming you have called your the child form using:

Form2 form = new Form2();
form.Show(this);

这篇关于从另一个表单完全访问控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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