首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

面试题,解决方法

2012-09-11 
面试题,winform 程序1.form 窗体有内有两个用户控件,为1,和2;控件1有1个标签。两个文本框,一个but2有一个

面试题,
winform 程序

1.form 窗体有内有两个用户控件,为1,和2;
控件1有1个标签。两个文本框,一个but;

2有一个标签,一个文本框一个but;

逻辑
动态加载控件1,当点击控件一中的按钮时把控件1中的第一个txt文本框数据传入控件2内的标签,

当点击控件2中的按钮把控件而中的txt文本输入控件一中的标签,



[解决办法]

C# code
1、定义两个,公共属性。   public string lblText{get;this.lable.text = value};      public string lblText2{get;this.lable2.text = value};      然后 this.textbox.text = lblText;
[解决办法]
控件1:
C# code
using System;using System.Collections.Generic;using System.ComponentModel;using System.Drawing;using System.Data;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace WindowsFormsControlLibrary1{    public partial class UserControl1: UserControl    {        public UserControl1()        {            InitializeComponent();        }        private string text1;        public string Text1        {            get { return text1; }            set             {                 text1 = value;                this.label1.Text = text1;            }        }        public  delegate void myDelegate(eventData e);        public  event myDelegate btClick;        private void button1_Click(object sender, EventArgs e)        {            this.text1 = this.textBox1.Text;//单点击按钮时            eventData _eventdata=new eventData();            _eventdata.tempData=this.Text1;            if (btClick!=null)            {                btClick(_eventdata);            }        }    }    public class eventData : EventArgs    {        public string tempData;    }} 

热点排行