日期:2014-05-18  浏览次数:21028 次

C#判断控件是否存在!!跨窗体操作问题!!
1.用代码创建窗体上所有控件,判断如果存在该控件则不创建,不存在则创建,请问如何实现?

2.如何实现跨窗体关闭窗口。譬如在from1上有butten1,单击butten1在from2上创建个butten2,单击butten2关闭from2,怎么来实现?

------解决方案--------------------
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TreeView treeView1;
private System.Windows.Forms.ListView listView1;
private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;
private System.Windows.Forms.ToolStripMenuItem aaToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem bbbToolStripMenuItem;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.ListBox listBox2;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.PictureBox pictureBox1;

private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.button1 = new System.Windows.Forms.Button();
this.treeView1 = new System.Windows.Forms.TreeView();
this.listView1 = new System.Windows.Forms.ListView();
this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
this.aaToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.bbbToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.textBox1 = new System.Windows.Forms.TextBox();
this.listBox1 = new System.Windows.Forms.ListBox();
this.listBox2 = new System.Windows.Forms.ListBox();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.contextMenuStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout();
// 
// button1
// 
this.button1.Location = new System.Drawing.Point(9, 66);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(48, 36);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.UseCompatibleTextRendering = true;
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
// 
// treeView1
// 
this.treeView1.Location = new System.Drawing.Point(178, 0);
this.treeView1.Name = "treeView1";
this.treeView1.Size = new System.Drawing.Size(269, 348);
this.treeView1.TabIndex = 1;
this.treeView1.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView1_AfterSelect);
this.treeView1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.treeView1_KeyDown);
this.treeView1.AfterExpand += new System.Windows.Forms.TreeViewEventHandler(this.treeView1_AfterExpand);
// 
// listView1
// 
this.listView1.ContextMenuStrip = this.contextMenuStrip1;
this.listView1.Location = new System.Drawing.Point(14, 122);
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(128, 111);
this.listView1.TabIndex = 2;
this.listView1.UseCompatibleStateImageBehavior = false;
this.listView1