问题场景:
WinForm中的一个用户自定义控件(UserControl)为父窗体(内含一个button,一个TextBox),点击父窗体UserControl的Button后,弹出一个WinForm的子窗体,子窗体包括一个button,一个TextBox两个控件,在弹出WinForm窗体的textBox中完成输入后点击button,子窗体的关闭,父窗体UserControl的TextBox值更新为子窗体输入的内容,请问如何实现。
WinForm中的一个用户自定义控件(UserControl)为父窗体(内含一个button,一个TextBox),点击父窗体UserControl的Button后,弹出一个WinForm的子窗体,子窗体包括一个button,一个TextBox两个控件,在弹出WinForm窗体的textBox中完成输入后点击button,子窗体的关闭,父窗体UserControl的TextBox值更新为子窗体输入的内容,请问如何实现。
*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) http://feiyun0112.cnblogs.com/
不行,场景是自定义空间和WinForm交互。。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Button1_Click(object sender, EventArgs e)
{
frmChild f = new frmChild();
if (f.ShowDialog() == DialogResult.OK)
{
this.TextBox1.Text = f.Info;
} }
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace WindowsFormsApplication1
{
public partial class frmChild : Form
{
public frmChild()
{
InitializeComponent();
} public string Info
{
get { return this.TextBox1.Text; }
}
private void frmChild_Load(object sender, EventArgs e)
{
this.Button1.DialogResult = DialogResult.OK;
}
}
}
Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim f As New frmChild
AddHandler f.Info, AddressOf ChangeInfo
f.ShowDialog()
End Sub Private Sub ChangeInfo(ByVal txt As String)
Me.TextBox1.Text = txt
End SubEnd ClassPublic Class frmChild Public Event Info(ByVal txt As String) Private Sub frmChild_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Button1.DialogResult = Windows.Forms.DialogResult.OK
End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
RaiseEvent Info(Me.TextBox1.Text)
End Sub
End Class
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Button1_Click(object sender, EventArgs e)
{
frmChild f = new frmChild();
f.Info += ChangeInfo;
f.ShowDialog();
} private void ChangeInfo(string txt)
{
this.TextBox1.Text = txt;
} }
public partial class frmChild : Form
{
public frmChild()
{
InitializeComponent();
} public event InfoEventHandler Info;
public delegate void InfoEventHandler(string txt); private void frmChild_Load(object sender, EventArgs e)
{
this.Button1.DialogResult = DialogResult.OK;
} private void Button1_Click(object sender, EventArgs e)
{
if (Info != null)
{
Info(this.TextBox1.Text);
} }
}