public void Load(string[] files) { this.Controls.Clear(); this.SuspendLayout(); foreach (string str in files) { ImgPanel img = new ImgPanel(); img.MouseClick += Img_MouseClick; img.MouseDoubleClick += (sender, e) => { _itemdoubleclick?.Invoke(sender, e); }; this.Controls.Add(img); } this.ResumeLayout(); _index = 0; _count = files.Length; _threadindex = 0; _files = files; _start = 0; Thread[] thread = new Thread[_threadcount]; for (int i = 0; i < _threadcount; ++i) { thread[i] = new Thread(new ThreadStart(Start)); thread[i].IsBackground = true; thread[i].Start(); } }
//protected override void OnKeyDown(KeyEventArgs e) //{ // if (e.Modifiers==Keys.Control && e.KeyData == Keys.A) // { // } // base.OnKeyDown(e); //} public void CtrlA() { for (int i = 0; i < this.Controls.Count; i++) { ImgPanel ip = this.Controls[i] as ImgPanel; if (!ip.Selected) { ip.Selected = true; } } }
public string[] GetSelectedImg() { List <string> imagePathList = new List <string>(); for (int i = 0; i < this.Controls.Count; i++) { ImgPanel ip = this.Controls[i] as ImgPanel; if (ip.Selected) { imagePathList.Add(ip.File); } } return(imagePathList.ToArray()); }
/// <summary> /// 控件选择 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Img_MouseClick(object sender, MouseEventArgs e) { ImgPanel img = sender as ImgPanel; if (Control.ModifierKeys == Keys.Control) { img.Selected = !img.Selected; _start = this.Controls.GetChildIndex(img); } else if (Control.ModifierKeys == Keys.Shift) { int index = this.Controls.GetChildIndex(img); int start = _start > index ? index : _start; int end = _start > index ? _start : index; int len = this.Controls.Count; for (int i = 0; i < len; ++i) { if (i >= start && i <= end) { (this.Controls[i] as ImgPanel).Selected = true; } else { (this.Controls[i] as ImgPanel).Selected = false; } } } else { foreach (ImgPanel panel in this.Controls) { panel.Selected = false; } img.Selected = true; _start = this.Controls.GetChildIndex(img); } _itemClick?.Invoke(sender, e); }