问题是这样的:有3个窗体 一个主窗体form1, 还有form2和form3form2上有个textbox控件,form3上有个textbox控件和一个button控件;form3上的textbox.text="你好"; 点击form3上的button后使form2中的textbox内容等于form3中的textbox内容,应该怎么做,请各位大哥大姐指教,急切等待中.
解决方案 »
- 打开窗体实例化问题?
- 这是个Odbc的什么错误?
- 当TextBox.Select(start,length)选择的内容需要拉动滚动才能看见时,怎样自动滚动选择内容到最顶?
- sql语句里发生错误:The left-hand side of an assignment must be a variable
- 请问c#下如何能调用ocx或动态库dll
- web系统开发过程中,命名空间一般是什么时候才增加的?好象留言本跟论坛,他们的命名空间是怎么定呢?
- 请教一个正则表达式
- C#的GENERIC机制
- 关于论坛的一个问题
- 为什么第二次运行exe文件会快一点?
- FileInfo[]中的元素排序问题
- 高分求.NET服务的安装
{
Control _Control = _From.Controls["Form2的TextBox.Name"];
if (_Control != null) _Control.Text = "设置值";
}
form3的button点击后,直接修改静态变量的textbox.Text属性
public static Form f2 = new form2();//这个form2需要记录下来,这样后面的form3才能访问到。
f2.TextBox1.Text = this.Textbox1.Text; //form3上执行这一句代码,f2上的Textbox1需要改成public属性,默认是private的,外部不能访问。
打开form2和form3的时候把窗体添加进Dictionary,并给唯一标识名称
点中form3的BUTTON时先判断是否为空
if (Dictionary["form2"] == null || Dictionary["form3"].IsDisposed)
然后Dictionary["form2"].TextBox1.Text=Dictionary["form3"].TextBox1.TextTextBox1需要声明为Public
能举个例子提示一下吗?相关的也可以>
===》
if (Dictionary["form2"] != null)
//form3中
private void buttonOnClink(object sender, EventArgs e)
{
Form2 fr = new Form2();
fr.textBox1.Text= this.textBox1.Text;
fr.Show();
}
建立一个 Dictionary <string, Form>
打开form2和form3的时候把窗体添加进Dictionary,并给唯一标识名称.这个该怎么做啊,刚学,不太懂,请多指教.我试了上面发的好多不行,这个问题在VB.net中很好实现,但是在C#中就不知道该怎么实现了
帮忙啊
给分吧。
.....
form2 form2instance = new form2();
testDict.Add("form2", form2instance );
form3 form3instance = new form3();
testDict.Add("form3", form3instance );
caozhy大哥太有魅力了
真是太感谢了,thank you
揭贴了 谢谢大家的支持.有大家的支持才有我发贴的动力.
用委托的方式是说一个窗体的控件内容改变后(当然也可以是WebService接收到数据,或者SOCKET底层接收到数据,或者数据库访问层定时更新等等多种情况),抛出一个事件,
而先前需要做一个委托,接收到这个数据改变的事件后去改变其它窗体控件的内容(一般在窗体上写一个函数,接收数据并修改控件的值,委托去调用该窗体函数并传递数据)。
呵呵,今天开心,第5次连任MVP,上来逛逛!
FORM1.CS
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication8
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
Form2 frm = new Form2();
frm.Show();
Form3 frm3 = new Form3(frm);
frm3.Show();
}
}
}
FORM2.CS
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication8
{
public delegate void calleventhandler(string strMsg);
public partial class Form2 : Form
{
public event calleventhandler eventmsg;
public Form2()
{
InitializeComponent();
}
public void Run(string strMsg)
{
if (eventmsg != null)
{
eventmsg(strMsg);
}
}
public void RecvMsg(string strMsg)
{
this.textBox2.Text = strMsg;
}
}
}
FORM3.CS
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication8
{
public partial class Form3 : Form
{
Form2 frm;
public Form3(Form2 frm)
{
InitializeComponent();
this.frm = frm;
} private void button1_Click(object sender, EventArgs e)
{
frm.eventmsg += new calleventhandler(frm.RecvMsg);
frm.Run(this.textBox1.Text);
}
}
}