从子窗体更改文本框的文字母 [英] Change textbox text parent from child form

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

问题描述

我在我的程序有两种形式。我有一个文本框,并在两人面前的按钮。当我在Form1中点击按钮,使用的ShowDialog()显示窗体2;
当我在文本框的窗口2键入并以这种形式按一下按钮,窗口2关闭,重点是在Form1上,而我在窗口2型转移到Form1上放置一个文本框中的文本。



我应该怎么做呢?


解决方案

  1. 保留在Form1到被显示为一个对话框

  2. 中的窗体2的实例的引用
  3. 揭露窗口2给文本框的内容在窗口2的公共属性

  4. 在当前窗口2关闭的下一行代码要访问此属性,并使用它的值来填充在文本框中Form1上,



是这样的:

 窗口窗口2 =新Form2的(); 
form2.ShowDialog();
this.textBox1 = form2.TextBoxValue;



其中,窗口2 有一个属性定义:

 公共字符串TextBoxValue {
{返回textBox2.Text; }
}


I have two forms in my program. I have a textbox and a button in both of them. when I click on button in form1, form2 is displayed using showdialog(); When I type in textbox in form2 and click on the button in this form, form2 closes and focus is on form1 and the text that I type in form2 is transferred to a textbox on form1.

How should I do this?

解决方案

  1. Hold a reference in form1 to the instance of form2 that is being shown as a dialog
  2. Expose a public property in form2 giving the contents of the textbox in form2
  3. When form2 closes, the next line of code should access this property and use its value to populate the textbox in form1,

Something like:

Window form2 = new Form2();
form2.ShowDialog();
this.textBox1 = form2.TextBoxValue;

Where form2 has a property defined:

public string TextBoxValue {
  get { return textBox2.Text; }
}

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

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