1.多个btn绑定同一事件操作
this.linkLabel1.Click += myBtn_click;
private void myBtn_click(object sender, EventArgs e)
{
LinkLabel btn = (LinkLabel)sender;
MessageBox.Show(btn.Name.ToString());
}
2.调用invoke修改界面ui
private void button1_Click(object sender, EventArgs e)
{
this.Invoke(new Action(() =>
{
this.button1.Text = "123";
}));
}
3.listView1
private void init()
{
// listview样式设置
listView1.GridLines = true;
listView1.FullRowSelect = true;
listView1.View = View.Details;
listView1.Scrollable = false;
listView1.MultiSelect = false;
listView1.HeaderStyle = ColumnHeaderStyle.Clickable;
// 表头设置
listView1.Columns.Add("ID", 50, HorizontalAlignment.Center);
listView1.Columns.Add("姓名", 50, HorizontalAlignment.Center);
listView1.Columns.Add("性别", 50, HorizontalAlignment.Center);
listView1.Columns.Add("年龄", 50, HorizontalAlignment.Center);
listView1.Columns.Add("学校", 150, HorizontalAlignment.Center);
listView1.Columns.Add("联系电话", 150, HorizontalAlignment.Center);
for (int i = 0; i < 3;i++ )
{
ListViewItem item = new ListViewItem();
item.SubItems.Clear();
item.Text = "id"+i;
item.SubItems.Add("Name" + i);
item.SubItems.Add("Gender" + i);
item.SubItems.Add("Age" + i);
item.SubItems.Add("University" + i);
item.SubItems.Add("Phone" + i);
listView1.Items.Add(item);
}
// listview样式设置
listView2.GridLines = true;
listView2.FullRowSelect = true;
listView2.View = View.Details;
listView2.Scrollable = false;
listView2.MultiSelect = false;
listView2.HeaderStyle = ColumnHeaderStyle.Clickable;
// 表头设置
listView2.Columns.Add("ID", 50, HorizontalAlignment.Center);
listView2.Columns.Add("姓名", 50, HorizontalAlignment.Center);
listView2.Columns.Add("性别", 50, HorizontalAlignment.Center);
listView2.Columns.Add("年龄", 50, HorizontalAlignment.Center);
listView2.Columns.Add("学校", 150, HorizontalAlignment.Center);
listView2.Columns.Add("联系电话", 150, HorizontalAlignment.Center);
for (int i = 3; i < 6; i++)
{
ListViewItem item = new ListViewItem();
item.SubItems.Clear();
item.Text = "id" + i;
item.SubItems.Add("Name" + i);
item.SubItems.Add("Gender" + i);
item.SubItems.Add("Age" + i);
item.SubItems.Add("University" + i);
item.SubItems.Add("Phone" + i);
listView2.Items.Add(item);
}
}
private void listView1_DoubleClick(object sender, EventArgs e)
{
ListViewItem item=this.listView1.SelectedItems[0];
this.listView1.SelectedItems[0].Remove();
this.listView2.Items.Add(item);
}
4.排序
var list = dtoInList.FindAll(t => t.Combo_no == dto.Combo_no);
list.Sort((a, b) => a.Rn.CompareTo(b.Rn));
dto.Rn = list.IndexOf(dto) + 1;
转载:https://blog.csdn.net/qq_41515170/article/details/101453213