我的认为是在点击按钮是调用form2 form2 for = new form2 如果需要里面的只得值 那就定个公共的变量 当点击按钮时就把form2里的值放到公共变量里面,要显示在form1里那就把放在公共变量的值拿出来
查找替换操作的 delegate 声明, 以及查找替换对话框的构造函数. public delegate void FindReplaceResetDelegate(); public delegate bool FindFirstDelegate(string findText, bool matchWhole, bool matchCase); public delegate bool FindNextDelegate(string findText, bool matchWhole, bool matchCase); public delegate bool FindReplaceOneDelegate(string findText, string replaceText, bool matchWhole, bool matchCase); public delegate int FindReplaceAllDelegate(string findText, string replaceText, bool matchWhole, bool matchCase); public FindReplaceForm(string initText, FindReplaceResetDelegate resetDelegate, FindFirstDelegate findFirstDelegate, FindNextDelegate findNextDelegate, FindReplaceOneDelegate replaceOneDelegate, FindReplaceAllDelegate replaceAllDelegate) {
class Form1 { int x; public Form1(int v)//构造函数传值 { this.x=v; } pubic int X { set{this.x=value;}//公共属性传值 } public void setData(int v) {this.x=v;}//方法传值 }要取值,必须有拥有一个该对象的引用: class Form2 { Form1 f=new Form1();//包含的形式,可以取f的公共的属性 事件 方法等
里面是我写的,比较详细,可以参考下
public delegate void FindReplaceResetDelegate();
public delegate bool FindFirstDelegate(string findText, bool matchWhole, bool matchCase);
public delegate bool FindNextDelegate(string findText, bool matchWhole, bool matchCase);
public delegate bool FindReplaceOneDelegate(string findText, string replaceText, bool matchWhole, bool matchCase);
public delegate int FindReplaceAllDelegate(string findText, string replaceText, bool matchWhole, bool matchCase); public FindReplaceForm(string initText,
FindReplaceResetDelegate resetDelegate,
FindFirstDelegate findFirstDelegate,
FindNextDelegate findNextDelegate,
FindReplaceOneDelegate replaceOneDelegate,
FindReplaceAllDelegate replaceAllDelegate)
{
{
int x;
public Form1(int v)//构造函数传值
{
this.x=v;
}
pubic int X
{
set{this.x=value;}//公共属性传值
}
public void setData(int v)
{this.x=v;}//方法传值
}要取值,必须有拥有一个该对象的引用:
class Form2
{
Form1 f=new Form1();//包含的形式,可以取f的公共的属性 事件 方法等
void Function(Form1 f)
{ f.X=100;}//将对象引用作为参数传给方法的形式
}
两个窗体就是两个类,两个类之间要取值传值,要么通过公共的方法属性事件委托等等,要么通过我中有你,你中有我的包含形式,或者由第三方来包含,不外乎这向种方法
让 1.在form1里定义一个方法
必须是public的啊
public void str(string str)
{
//实现一下吧你要实现的功能
}2.接着看,在你调用Form2的时候一定要这样写这里才是关键
form2 f2=new form2();
//这样代表两个窗体用的是同一个实例,也只有这样才能实现你的效果, 试试吧
f2.objform1=this;
f2.Show();
//为什么要这样写呢,因为这样可以让两个窗体的Form1对象成为一个对象这样才能,达到你要的效果。3.你再看在Form2里定义一个变量 //不要New啊
Form1 objform1; 然后在Form2的Button事件里写
objform1.str(传一个参数);