问题场景:
WinForm中的一个用户自定义控件(UserControl)为父窗体(内含一个button,一个TextBox),点击父窗体UserControl的Button后,弹出一个WinForm的子窗体,子窗体包括一个button,一个TextBox两个控件,在弹出WinForm窗体的textBox中完成输入后点击button,子窗体的关闭,父窗体UserControl的TextBox值更新为子窗体输入的内容,请问如何实现。

解决方案 »

  1.   

    在程序里面设置一个public变量,在弹出的子窗体的构造函数里面为这个public变量赋值,再获取这个变量值。
      

  2.   

    做个窗体 用ShowDialog()来做..这不难把..还是我理解错了.
      

  3.   

    UserControl提供属性设置TextBox的值
      
    *****************************************************************************
    欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) http://feiyun0112.cnblogs.com/
      

  4.   

    在程序里面设置一个public变量,在弹出的子窗体的button事件里面里面为这个public变量赋子窗体中textbox值,再获取这个变量值赋给主窗体中的textbox。
      

  5.   

    弹出和获取返回值都简单,但就是不知道怎么把返回值在父窗体的textBox里显示出来,Form1 f1 = (Form1)this.Owner;地方法编译不过,因为父窗体是userControl...
      

  6.   


    不行,场景是自定义空间和WinForm交互。。
      

  7.   

    把usercontrol里面的textbox设置为一个对应的属性阿
      

  8.   


    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;
            }
        }
    }
      

  9.   


    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
      

  10.   


    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);
                }         }
        }