winform:C#如何实现两个WINFORM之间的访问



在VB中我们通常可以通过form1!text1.text等进行窗体的间访问但是在C#中我们发现这样是行区别通过我这几天研究终于想出了进行两个WINFORM的间访问办法那就是通过个中间类进行例子控制代码如下:
//=
Form1.cs
//=
using ;
using .Drawing;
using .Collections;
using .ComponentModel;
using .Windows.Forms;
using .Data;

WA_Test1
{
/// <summary>
/// 作者:Davi
/// </summary>
//委托
public delegate chktext( myInt);

public Form1 : .Windows.Forms.Form
{
private .Windows.Forms.Button button1;
public .Windows.Forms.TextBox textBox1;
//public Form1 frm1= Form1;
/// <summary>
/// 必需设计器变量
/// </summary>
private .ComponentModel.Container components = null;

public Form1
{
//
// Windows 窗体设计器支持所必需
//
InitializeComponent;

//
// TODO: 在 InitializeComponent 后添加任何构造代码
//
}

/// <summary>
/// 清理所有正在使用资源
/// </summary>
protected override void Dispose( bool disposing )
{
( disposing )
{
(components != null)
{
components.Dispose;
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需思路方法 - 不要使用代码编辑器修改
/// 此思路方法内容
/// </summary>
private void InitializeComponent
{
this.button1 = .Windows.Forms.Button;
this.textBox1 = .Windows.Forms.TextBox;
this.SuspendLayout;
//
// button1
//
this.button1.Location = .Drawing.Po(128, 56);
this.button1.Name = \"button1\";
this.button1.Size = .Drawing.Size(56, 24);
this.button1.TabIndex = 0;


this.button1.Text = \"button1\";
this.button1.Click .EventHandler(this.button1_Click);
//
// textBox1
//
this.textBox1.Location = .Drawing.Po(16, 56);
this.textBox1.Name = \"textBox1\";
this.textBox1.Size = .Drawing.Size(88, 21);
this.textBox1.TabIndex = 1;
this.textBox1.Text = \"textBox1\";
//
// Form1
//
this.AutoScaleBaseSize = .Drawing.Size(6, 14);
this.ClientSize = .Drawing.Size(304, 117);
this.Controls.AddRange( .Windows.Forms.Control {
this.textBox1,
this.button1});
this.MaximizeBox = false;
this.Name = \"Form1\";
this.Text = \"Form1\";
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// 应用主入口点
/// </summary>
[STAThread]
void Main
{
Form3 frm3= Form3;
Application.Run(frm3.GetForm1);
}

private void button1_Click(object sender, .EventArgs e)
{
Form3 frm3= Form3;
(frm3.GetForm2).Show;
//frm3.InputBox(\"Title\",\"please enter some value\",\"20\");
//MessageBox.Show(frm3.InputBox.);
}

private void button2_Click(object sender, .EventArgs e)
{
//
}

}
}
//=
Form2.cs
//=
using ;
using .Drawing;
using .Collections;
using .ComponentModel;
using .Windows.Forms;

WA_Test1
{
/// <summary>


/// 作者:Davi
/// </summary>
public Form2 : .Windows.Forms.Form
{
private .Windows.Forms.TextBox textBox1;
private .Windows.Forms.Button button1;
/// <summary>
/// 必需设计器变量
/// </summary>
private .ComponentModel.Container components = null;

public Form2
{
//
// Windows 窗体设计器支持所必需
//
InitializeComponent;

//
// TODO: 在 InitializeComponent 后添加任何构造代码
//
}

/// <summary>
/// 清理所有正在使用资源
/// </summary>
protected override void Dispose( bool disposing )
{
( disposing )
{
(components != null)
{
components.Dispose;
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需思路方法 - 不要使用代码编辑器修改
/// 此思路方法内容
/// </summary>
private void InitializeComponent
{
this.textBox1 = .Windows.Forms.TextBox;
this.button1 = .Windows.Forms.Button;
this.SuspendLayout;
//
// textBox1
//
this.textBox1.Location = .Drawing.Po(16, 40);
this.textBox1.Name = \"textBox1\";
this.textBox1.Size = .Drawing.Size(152, 21);
this.textBox1.TabIndex = 0;
this.textBox1.Text = \"textBox1\";
//
// button1
//
this.button1.Location = .Drawing.Po(56, 72);
this.button1.Name = \"button1\";
this.button1.Size = .Drawing.Size(168, 24);


this.button1.TabIndex = 1;
this.button1.Text = \"更改Form1TextBox1\";
this.button1.Click .EventHandler(this.button1_Click);
//
// Form2
//
this.AutoScaleBaseSize = .Drawing.Size(6, 14);
this.ClientSize = .Drawing.Size(272, 117);
this.Controls.AddRange( .Windows.Forms.Control {
this.button1,
this.textBox1});
this.Name = \"Form2\";
this.Text = \"Form2\";
this.ResumeLayout(false);

}
#endregion

private void button1_Click(object sender, .EventArgs e)
{
Form3 frm3= Form3;
(frm3.GetForm1).textBox1.Text=this.textBox1.Text;
}
}
}
//=
Form3.cs
//=
using ;
using .Drawing;
using .Collections;
using .ComponentModel;
using .Windows.Forms;

WA_Test1
{
/// <summary>
/// 作者:Davi
/// </summary>
public Form3
{
/// <summary>
/// 必需设计器变量
/// </summary>
private Form1 frm1;
private Form2 frm2;
public Form3
{
/// <summary>
/// 清理所有正在使用资源
/// </summary>
}
public void CreateForm1
{
frm1= Form1;
}
public void CreateForm2
{
frm2= Form2;
}
public Form1 GetForm1
{
(frm1null)
{
CreateForm1;


}
frm1;
}
public Form2 GetForm2
{
(frm2null)
{
CreateForm2;
}
frm2;
}
}
/// <summary>
/// 输入框窗体
/// </summary>
}
*欢迎大家和我起研究
Tags:  winformxml winform打印 winformtreeview winform

延伸阅读

最新评论

发表评论