110,579
社区成员
发帖
与我相关
我的任务
分享
//主窗体
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Collections;
using System.Windows.Forms;
namespace ShowForm1
{
public partial class FormShowEmployees : Form
{
private ArrayList arr;
public FormShowEmployees()
{
InitializeComponent();
arr = new ArrayList();
arr.Add("AAA");
arr.Add("BBB");
arr.Add("CCC");
arr.Add("DDD");
arr.Add("EEE");
this.listboxshowEmployees.DataSource = arr;
}
private void buttonEdit_Click(object sender, EventArgs e)
{
FormEditEmployees fedit = new FormEditEmployees(arr);
// fedit.Owner = this;
fedit.ShowDialog(this);
}
private void buttonExit_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
//子窗体
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ShowForm1
{
public partial class FormEditEmployees : Form
{
private System.Collections.ArrayList arr;
public FormEditEmployees( System.Collections.ArrayList arr1)
{
InitializeComponent();
arr = arr1;
foreach (object o in arr1)
{
this.listboxshow.Items.Add(o.ToString());
}
}
private void buttonAdd_Click(object sender, EventArgs e)
{
string str = this.textadd.Text.Trim().ToString();
if (str != "")
{
arr.Add(str);
this.listboxshow.Items.Add(str);
//FormEditEmployees fee = new FormEditEmployees();
//fee.Owner = this;
}
else
{
MessageBox.Show("Erorr");
}
}
private void buttondel_Click(object sender, EventArgs e)
{
int id = this.listboxshow.SelectedIndex;
if (id != -1)
{
arr.RemoveAt(id);
this.listboxshow.Items.RemoveAt(id);
}
else
{
MessageBox.Show("Erorr");
}
}
private void buttonClear_Click(object sender, EventArgs e)
{
//FormShowEmployees fshow = (FormShowEmployees)this.Owner;
this.Close();
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace 事件委托2
{
public partial class Form1 : Form
{
Form2 frm = new Form2();
public Form1()
{
InitializeComponent();
frm.Show();
frm.Hide();
}
public delegate void mydelegate(string text);//定义一个委托
public static event mydelegate myevent;
private void listBox1_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (myevent != null)
{
myevent(this.listBox1.SelectedItem.ToString());
}
}
private void button1_Click(object sender, EventArgs e)
{
frm.Show();
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace 事件委托2
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
Form1.myevent += new Form1.mydelegate(fm2_myevent);
}
void fm2_myevent(string str)
{
this.listBox1.Items.Add(str);
}
}
}