定义一个静态变量啊
From1中Public static String str = null;str =你想要的值 在From2中调用 From1.str 就行了 不过你问题没有说的明白 说的再明白点 怎么关联啊?
From1中Public static String str = null;str =你想要的值 在From2中调用 From1.str 就行了 不过你问题没有说的明白 说的再明白点 怎么关联啊?
解决方案 »
- 怎样实现RichTextBox中的图文混排,文本是从数据库中导出,图片存的是路径
- C# winform中 tabcontrol 的美化问题,急救
- C# 中如何使用AxShockwaveFlash控件
- 请问怎么用C#来播放和控制IFO呢???就是DVD那样可以控制
- 关于listview的一个问题
- 一个简单的正则表达室
- foreach(ListViewItem lvt in list)有问题么?
- 大侠们,怎么知道mysql数据库已经备份和恢复完成?
- 更新数据后怎么刷新页面
- 如何把一个独立的窗体嵌入在另一个窗体内!!
- LisrView 添加项到指定的列和指定的组?
- 求助:老板叫我做一个只允许一台机只能执行某程序,其他程序都不能执行应该怎么样做啊?
把FROM1的listbox值当参数传给FROM2
在FROM2中定义个变量记录下
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;namespace 窗体中的值传递
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.ListBox listBox1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.listBox1 = new System.Windows.Forms.ListBox();
this.SuspendLayout();
//
// listBox1
//
this.listBox1.ItemHeight = 12;
this.listBox1.Items.AddRange(new object[] {
"我要分",
"我要接分"});
this.listBox1.Location = new System.Drawing.Point(88, 32);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(120, 52);
this.listBox1.TabIndex = 1;
this.listBox1.DoubleClick += new System.EventHandler(this.listBox1_DoubleClick);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.listBox1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
} private void listBox1_DoubleClick(object sender, System.EventArgs e)
{
string Value=listBox1.Text.ToString();
Form2 form=new Form2(Value);
form.Show();
}
}
}
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;namespace 窗体中的值传递
{
/// <summary>
/// Form2 的摘要说明。
/// </summary>
public class Form2 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private string _Value;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public Form2(string Value)
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
this._Value=Value; //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(40, 40);
this.textBox1.Name = "textBox1";
this.textBox1.TabIndex = 0;
this.textBox1.Text = "";
//
// Form2
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.textBox1);
this.Name = "Form2";
this.Text = "Form2";
this.Load += new System.EventHandler(this.Form2_Load);
this.ResumeLayout(false); }
#endregion private void Form2_Load(object sender, System.EventArgs e)
{
textBox1.Text=_Value;
}
}
}
From2 SHOW的时候把这个参数的值设为From1 ListBox里的选中的行的值
如在你双击listbox中的一行时,就会触发该事件,然后把那个textbox控件的visible=true,然后把双击的那行值赋给textbox的Text属性,事件数据e,貌似应该会有个e.rowindex什么的可以得到你当前双击的那行,然后listbox[e.rowindex],是这样?我也是个新手,多多包含