问题描述:
有一窗口form1 上有一个UserControl 和一个textBox
UserControl里有一个treeView问题: 如何在双击treeView的结点时,在textBox中显示 所点击结点的名称要求:我知道如何用event delegate做,请问有谁知道如何声明接口,用接口技术做 ,
Thx!
有一窗口form1 上有一个UserControl 和一个textBox
UserControl里有一个treeView问题: 如何在双击treeView的结点时,在textBox中显示 所点击结点的名称要求:我知道如何用event delegate做,请问有谁知道如何声明接口,用接口技术做 ,
Thx!
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using WindowsControlLibrary1;namespace WindowsApplication4
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form,IUserControl
{
.........................
#region IUserControl 成员 public void OnItemActivate(string _text)
{
// TODO: 添加 Form1.OnItemActivate 实现
this.textBox1.Text = _text;
} #endregion
}}using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;namespace WindowsControlLibrary1
{
............... private void listView1_ItemActivate(object sender, System.EventArgs e)
{
IUserControl myIUserControl = this.ParentForm as IUserControl;
if(null != myIUserControl)
{
myIUserControl.OnItemActivate(listView1.SelectedItems[0].Text);
}
}
}
public interface IUserControl
{
void OnItemActivate(string _text);
}
}
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using WindowsControlLibrary1;namespace WindowsApplication4
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form,IUserControl
{
.........................
#region IUserControl 成员 public void OnItemActivate(string _text)
{
// TODO: 添加 Form1.OnItemActivate 实现
this.textBox1.Text = _text;
} #endregion
}}using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;namespace WindowsControlLibrary1
{
............... private void listView1_ItemActivate(object sender, System.EventArgs e)
{
IUserControl myIUserControl = this.ParentForm as IUserControl;
if(null != myIUserControl)
{
myIUserControl.OnItemActivate(listView1.SelectedItems[0].Text);
}
}
}
public interface IUserControl
{
void OnItemActivate(string _text);
}
}