同时运行了两个窗体Form1,Form2
Form1上有个TextBox控件
form2上有个TreeView控件
怎样能够让点击TreeView节点时,TextBox上显示TreeView节点的Text属性
点击不同的节点TextBox上显示不同的文本
Form1上有个TextBox控件
form2上有个TreeView控件
怎样能够让点击TreeView节点时,TextBox上显示TreeView节点的Text属性
点击不同的节点TextBox上显示不同的文本
解决方案 »
- FileStream.Seek(0,SeekOrigin.Begin)不能正确回到文件头部的问题
- 关于抓包的网络编程
- 表单提交form action 和 response.redirect。。!
- 关于加密解密的数据库设计.
- C#打印程序在Windows98下的很迷惑的问题,居然打印出来的字符内容更改了,还有许多重复,急啊,谢谢大家了!!!
- 把C#代码放JavaSript 上的问题
- 搞 WinForm 的朋友可以看看
- 平时常说的csc命令怎样用?cs后缀的文件的区别是什么?
- 急!请问?
- 关于API中EnumChildWindows 这个的参数问题
- 关于dataGridView中数据库更新的问题
- 怎么将一个C#程序生成一个.EXE文件
2,Form2 的TreeView 的AfterSelect 事件:
Form1 frm = new Form1();
frm.TextBox1.Text =TreeView1.SelectedNode.Text;
frm.ShowDialog();
Form2 f2=new Form2();
f2.SelectedNodeChanged+=...
{
f1.SetTextBoxValue=SelectedNOde.Text;
};
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
{ TextBox txtBox;
Button btn; public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
txtBox = new TextBox();
btn = new Button();
btn.Click += OpenForm;
txtBox.Location = new Point(20, 10);
btn.Text = "Open form2";
btn.Location = new Point(20, 50);
this.Controls.Add(txtBox);
this.Controls.Add(btn);
} private void OpenForm(object sender, EventArgs e)
{
Form2 f = new Form2(txtBox);
f.Show();
} } public class Form2 : System.Windows.Forms.Form
{ private TextBox txtBox;
private TreeView tree; public Form2(TextBox mtxtBox)
{
txtBox = mtxtBox;
tree = new TreeView();
for (int i = 0; i <= 10; i++)
{
tree.Nodes.Add(new TreeNode(i.ToString()));
}
tree.Dock = DockStyle.Fill;
tree.AfterSelect += AfterSelect;
this.Controls.Add(tree);
} private void AfterSelect(object sender, TreeViewEventArgs e)
{
txtBox.Text = e.Node.Text;
} } }
Public Class Form1 Dim txtBox As TextBox
Dim btn As Button Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
txtBox = New TextBox
btn = New Button
AddHandler btn.Click, AddressOf OpenForm
txtBox.Location = New Point(20, 10)
btn.Text = "Open form2"
btn.Location = New Point(20, 50)
Me.Controls.Add(txtBox)
Me.Controls.Add(btn)
End Sub Private Sub OpenForm(ByVal sender As Object, ByVal e As EventArgs)
Dim f As New Form2(txtBox)
f.Show()
End Sub
End ClassPublic Class Form2
Inherits System.Windows.Forms.Form Private txtBox As TextBox
Private tree As TreeView Public Sub New(ByVal mtxtBox As TextBox)
txtBox = mtxtBox
tree = New TreeView
For i As Integer = 0 To 10
tree.Nodes.Add(New TreeNode(i.ToString))
Next
tree.Dock = DockStyle.Fill
AddHandler tree.AfterSelect, AddressOf AfterSelect
Me.Controls.Add(tree)
End Sub Private Sub AfterSelect(ByVal sender As Object, ByVal e As TreeViewEventArgs)
txtBox.Text = e.Node.Text
End SubEnd Class