使用线条技术,由主窗口窗体创建的黑板窗口窗体中有一个子文本框控制器,我想执行此功能:在主窗口窗体中,当我单击按钮(或Enter-key-down)时,它将文字传送到主窗口窗体中。我能做些什么呢?
What is the use of default keyword in C#? Is it introduced in C# 3.0 ?
使用线条技术,由主窗口窗体创建的黑板窗口窗体中有一个子文本框控制器,我想执行此功能:在主窗口窗体中,当我单击按钮(或Enter-key-down)时,它将文字传送到主窗口窗体中。我能做些什么呢?
您需要让 ChildWindow 向 MainWindow 发回消息。 以下示例应有用 :
public interface IListner
{
void Send(String message);
}
MainWindow
public partial class MainWindow : Window, IListner
{
public MainWindow()
{
InitializeComponent();
}
public void Send(string message)
{
// Read the message here.
// If this code is called from different thread, use "Dispatcher.Invoke()"
}
public void OpenAnotherWindow()
{
// Since "MainWindow" implements "IListner", it can pass it s own instance to "ChildWindow"
ChildWindow childWindow = new ChildWindow(this);
}
}
ChildWindow:
public partial class ChildWindow : Window
{
private IListner Listner { get; set; }
public ChildWindow(IListner listner)
{
InitializeComponent();
Listner = listner;
}
private void OnTextBoxTextChanged()
{
// This will call "Send" on "MainWindow"
Listner.Send(TextBox1.Text);
}
}
很快的谷歌会带回来很多结果...
最好的做法可能是,当您创建 Form2 (孩子) 时, 使用一种公共的方法, 您可以在 Form1 (父/母) 中通过, 然后在 Form1 中再次通过同样的方法, 但通过一个字符串, 而不是一个表。 因此, 您最终会遇到类似的情况 :
表格1 (父母):
private void Button1_Click_ShowChildForm(args..)
{
Form2 frm2 = new Form2();
frm2.Show();
frm2.GetInstance(this);
}
public void PassBack(string var)
{
TextBox1.Text = var;
}
表2 (儿童):
private static Form1 _frm1;
public void GetInstance(Form1 Frm1)
{
this._frm1 = Frm1;
}
private void Button2_Click_Close(args...)
{
_frm1.PassBack(this.TextBox2.Text);
this.Close();
}
类似这样的事情应该做这个把戏。 ) () ()
NB。你也许可以把它整理一下, 如果你真的想的话, 你可以推翻Form2的“显示”方法, 接受一个“表1”的例子, 而不是宣布一个单独的方法, 但你可以理解这个想法。
What is the use of default keyword in C#? Is it introduced in C# 3.0 ?
I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...
I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...
I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...
I have two EF entities. One has a property called HouseNumber. The other has two properties, one called StartHouseNumber and one called EndHouseNumber. I want to create a many to many association ...
How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...
Since I cannot order my dictionary, what is the best way of going about taking key value pairs and also maintaing an index?
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. ...