提示我" 找不到类型或命名空间名称“MyInvoke”(是否缺少 using 指令或程序集引用?)"
MyInvoke 写在你程序中的命名空间低下,不要写在类中,注意有public修饰
using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Text;namespace SnmpAplication { //写在这里... public delegate void MyInvoke(string Item1,string Item2,string Item3); //以下是Form1 public class frmSnmp : System.Windows.Forms.Form { //..... } }
在打开form2之前
将form1上的3个textbox的text赋给数组
在form2的load事件里把数组值加到listview里
在Form1中调用 fm2.addText(textbox1.text);
可以用属性构造函数事件等
http://community.csdn.net/Expert/TopicView3.asp?id=5166237
public delegate void MyInvoke(string Item1,string Item2,string Item3);//在窗体From2中有这么一个回调函数,用于在ListView里添加一个新项的:
private void UpdateListView(string Item1,string Item2,string Item3)
{
ListView1.Items.Add(Item1);
ListView1.Items[ListView1.Items.Count - 1].SubItems.Add(Item2);
ListView1.Items[ListView1.Items.Count - 1].SubItems.Add(Item3);
}//比如说点击Form2的一个按钮弹出Form1进行录入,在点击按钮的事件下:
//把委托传过去
Form1 frmEdit=new Form1(new MyInvoke(UpdateListView));
frmEdit.ShowDialog(this);//在Form1里定义一个属性
private MyInvoke mi=null;在构造函数中接收这个委托:
public Form1(MyInvoke myInvoke)
{
this.mi=myInvoke;
}//录入数据后,点击OK按钮,在点击事件下:
//回调
this.mi(this.TextBox1.Text,this.TextBox3.Text,this.TextBox3.Text);
this.Close();//关闭Form1
说明:以上代码没有测试过,但以前这么用过,虽然方法比较麻烦,但用起来不错,有问题再说...
建一个static 公共变量 如TempStr将form1的值传给tempstr
然后在form2中直接调用DB.TempStr
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Text;namespace SnmpAplication
{
//写在这里...
public delegate void MyInvoke(string Item1,string Item2,string Item3);
//以下是Form1
public class frmSnmp : System.Windows.Forms.Form
{
//.....
}
}
frmEdit.ShowDialog(this);然后将Form1的构造函数改成可以接收几个参数的就行了...