private void uc_OnOperatorClick(object sender) { UCList uclist = sender as UCList; int oldIndex = fm.uc1.Controls.IndexOf(uclist);//获取操作项的索引值 //移除操作项 fm.uc1.Controls.Remove(uclist); //对点击了删除按钮的用户控件 //让该用户控件后面的location都减一个h for (int i = oldIndex; i < fm.uc1.Controls.Count; i++) { if (fm.uc1.Controls[i] != null) { fm.uc1.Controls[i].Location = new Point(0, fm.uc1.Controls[i].Location.Y - uclist.Height); } } flag = true; j++; }
public void AddControl() { SqlConnection conn = new SqlConnection("Integrated Security=SSPI;Database=notebook;Server=."); conn.Open(); SqlCommand comm = new SqlCommand(); comm.CommandText = "select count(*) from tbl_note where title like '%" + fm.textBoxsearch.Text.Trim() + "%'"; comm.Connection = conn; int count = (int)comm.ExecuteScalar(); if (count > 0) { for (int i = 0; i < count; i++) { uclist = new UCList(); uclist.Location = new Point(0, h); uclist.addInfosearch(i); this.Controls.Add(uclist); h = h + uclist.Height; } } }
//点击保存后的增加用户控件的方法 public void AddControl() { uclist = new UCList(); uclist.Location = new Point(0, h); uclist.addInfo(); //点击用户控件上的删除按钮移除整个用户控件 uclist.OnOperatorClick += new UCList.OperatorEventHandler(uc_OnOperatorClick); //对当前新增的用户控件设置位置 if (flag == true) { h = h - j * uclist.Height; uclist.Location = new Point(0, h); this.Controls.Add(uclist); h = h + uclist.Height; flag = false; } else { this.Controls.Add(uclist); h = h + uclist.Height; } }