一直学的是ASP.NET 现在要用到智能客户端.. 赶着学了一下WinForm..
但碰到一个关于传值的问题.. 感觉和以前的VB差不多..方法1. 全局变量..
方法2. New出新的页面.. (??)
方法3. 静态变量.. 但是具体怎么做却是感觉力不从心.. 哪位能提供些具体的例子..代码.. 非常感谢...传值主要想用在这里..在C/S页面中点一个按钮.弹出一个小框框..(有点像日历控件)
然后点这框框里的某个值(TreeView中的一个节点), 再把这个值返回到弹出这个框框边上的文本框里.. 在线等.. 今天结贴... 再次谢谢各位..
但碰到一个关于传值的问题.. 感觉和以前的VB差不多..方法1. 全局变量..
方法2. New出新的页面.. (??)
方法3. 静态变量.. 但是具体怎么做却是感觉力不从心.. 哪位能提供些具体的例子..代码.. 非常感谢...传值主要想用在这里..在C/S页面中点一个按钮.弹出一个小框框..(有点像日历控件)
然后点这框框里的某个值(TreeView中的一个节点), 再把这个值返回到弹出这个框框边上的文本框里.. 在线等.. 今天结贴... 再次谢谢各位..
{
//想干么干么
}
private void button1_Click(object sender, System.EventArgs e)
{
frm2 frm = new frm2();
frm.Show();
frm.SetText +=new SetTextHanlder(this.SetText);
}
private void SetText(string s)
{
this.textBox1.Text = s;
}
frm2中:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;namespace WindowsApplication4
{
//定义委托
public delegate void SetTextHanlder(string s);
/// <summary>
/// frm2 的摘要说明。
/// </summary>
public class frm2 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;public frm2()
{
//
// 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.textBox1 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(56, 56);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(192, 21);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "textBox1";
//
// button1
//
this.button1.Location = new System.Drawing.Point(88, 120);
this.button1.Name = "button1";
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// frm2
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox1);
this.Name = "frm2";
this.Text = "frm2";
this.ResumeLayout(false);}
#endregion
//定义事件
public event SetTextHanlder SetText;
private void button1_Click(object sender, System.EventArgs e)
{
if(SetText != null)
{
this.SetText(this.textBox1.Text);
}
this.Close();
}
}
}
http://blog.csdn.net/tjvictor/archive/2006/06/23/824617.aspx
看了xfary(风飘摇) 的代码.. 再看过二楼的博客有点清楚了.. 谢谢..但现在问题又有了. 弹出的框框怎么定位置呢.. 我要弹出的框框的top left属性和接收的文本框的Top left+width. 我在Form2的构造函数里试过了不行. 不知道有其它办法没... 谢谢大家了..
http://blog.csdn.net/yumanqing/archive/2006/10/13/1333110.aspx
可以看看
控制窗体显示的位置,是要控制TOP和LEFT的,再Form_load中不可以吗?应该可以的