访问您需要使用的文本框数据 : textBox1. Text
窗体是一个对象,以便您定义更新文本框值的方法(您可以通过公共存取器暴露文本框本身)
如何将文本框值发送到两个表格之间的文本框, 不按按钮显示( ) / 显示Dialog( )? 我想要文本框的值不会打开窗体 。 p> div>
访问您需要使用的文本框数据 : textBox1. Text
窗体是一个对象,以便您定义更新文本框值的方法(您可以通过公共存取器暴露文本框本身)
要从父体向子女表格传递信息,您应在子女表格上创建一个属性,以获取需要的数据,然后在父体表格中设置该属性(例如,按键键)。
要让儿童表格将数据发送到父窗体中, 儿童表格中应该创建一个属性( 只需要是一个获取者), 并有它想要发送到父窗体中的数据。 然后它应该创建一个事件( 或者使用已有的 < code> Form code > 事件), 父窗体可以订阅 。
例如:
namespace PassingDataExample
{
public partial class ParentForm : Form
{
public ParentForm()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
ChildForm child = new ChildForm();
child.DataFromParent = "hello world";
child.FormSubmitted += (sender2, arg) =>
{
child.Close();
string dataFromChild = child.DataFromChild;
};
child.Show();
}
}
}
namespace PassingDataExample
{
public partial class ChildForm : Form
{
public ChildForm()
{
InitializeComponent();
}
public string DataFromParent { get; set; }
public string DataFromChild { get; private set; }
public event EventHandler FormSubmitted;
private void button1_Click(object sender, EventArgs e)
{
DataFromChild = "Hi there!";
if (FormSubmitted != null)
FormSubmitted(this, null);
}
}
}
我不懂你说的"没有秀()/秀(ShowDialog)()"到底是什么意思, 但是这无关紧要, 否则我会在这里进一步假设你有两个窗口都打开了(不管你是如何做到的)。
您希望避免将两种形式( 特别是像文本框等) 的实施细节( 而不是像文本框等) 混为一谈。 您可以与 < code> delegiates code > 和 < code> events code > 合作, 触发您两种形式之间的数据“ 发送 ” 。 您可以很容易地传递事件数据, 您的“ em” 被上传到其它形式( 或其他任何对象), 它不知道您表格的具体实施细节, 它只知道您通过代表( event) 收到的数据 。 我不打算在此张贴所有代码, 因为以下的 URL: < a href= http://www.codeproject.com/ artes/17371/Passing- Data- befer- Windows- Forms" rel=“ nofol > http://www.codeproject.com/ arts/173701/ Passing- Data- bey- Windows- Forms < / a > 。
I was wondering if someone can tell me what would be the best way to bring my application to the foreground if a mutex was not able to be created for a new instance. E.g.: Application X is running ...
I ve successfully created an app that minimizes to the tray using a NotifyIcon. When the form is manually closed it is successfully hidden from the desktop, taskbar, and alt-tab. The problem occurs ...
Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...
I have a DataTable that has several DataColumns and DataRow. Now i would like to handle an event when cell of this DataRow is changed. How to do this in c#?
How do you force a DataGridView to release its reference to a bound DataSet? We have a rather large dataset being displayed in a DataGridView and noticed that resources were not being freed after the ...
I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...
When I m trying to change the default Image of a Control on Windows Forms in Form Designer (no matter where on which control) I get this error: Error message: An item with the same key has ...
I have a Winforms application coded in VS C# 2008 and want to insert a WPF window into the window pane of Winforms application. Could you explain me how this is done.