大概这个问题已经在这里得到了答案,但我无法找到它.. 我有一个tabControl在每个标签页中的flowlayoutpanel,我可以在运行时添加控件。我可以重新排列它们,将它们跨标签页移动..我如何选择多个控件以便能够使用Ctrl +鼠标单击来移动它们?如何使用Ctrl键+鼠标点击选择多个控件?
这是迄今为止我拖事件:
private void control_DragDrop(object sender, DragEventArgs e)
{
Control target = new Control();
target.Parent = sender as Control;
if (target != null)
{
int targetIndex = FindCSTIndex(target.Parent);
if (targetIndex != -1)
{
string cst_ctrl = typeof(CustomControl).FullName;
if (e.Data.GetDataPresent(cst_ctrl))
{
Button source = new Button();
source.Parent = e.Data.GetData(cst_ctrl) as CustomControl;
if (targetIndex != -1)
fl_panel = (FlowLayoutPanel)tabControl1.SelectedTab.Controls[0];
if (source.Parent.Parent.Name == target.Parent.Parent.Parent.Name)
{
this.fl_panel.Controls.SetChildIndex(source.Parent, targetIndex);
}
else
{
target.Parent.Parent.Parent.Controls.Add(source.Parent);
this.fl_panel.Controls.SetChildIndex(source.Parent, targetIndex);
}
}
}
}
}
private int FindCSTIndex(Control cst_ctr)
{
fl_panel = (FlowLayoutPanel)tabControl1.SelectedTab.Controls[0];
for (int i = 0; i < this.fl_panel.Controls.Count; i++)
{
CustomControl target = this.fl_panel.Controls[i] as CustomControl;
if (cst_ctr.Parent == target)
return i;
}
return -1;
}
这是内置于Visual Studio中的设计器的一项功能。在运行时没有任何支持,您的表单的设计器视图与可以执行诸如显示选择矩形之类的东西的叠加窗口截然不同。只要点击一个控件就会让你头痛,当然这会触发控件的MouseDown事件。 VS设计师是一个多人一年的努力,而不是你将要开始的一个SO问题。自己利用设计器[这里覆盖](http://msdn.microsoft.com/en-us/magazine/cc163634.aspx)。 –