怎么回事,我有一个叫做imagePanel1的imagePanel (你可以把它看作一个picturePanel) (我把它导入了,这样我就不用做滚动条了:)
我在左边有一个treeView,我可以从witch拖动一个节点,并将其放到imagePanel上,在那里我可以获得拖放的位置,在这个位置上,我创建了一个名为panel1的普通面板,所以我做了100次,所以在最后我会有一个充满小面板的imagePanel…现在的问题是,当我单击imagePanel (面板所在的位置)时,我希望在MousePress上选择该面板,在mouseMove上移动该面板,在btnDelete上删除eventualLy……
下面是//***********************************************************************的imagePanel代码:
private void imagePanel1_DragDrop_1(object sender, DragEventArgs e)
{
Type testTip = new TreeNode().GetType();
YLScsImage.ImagePanel dropPicturePanel = (YLScsImage.ImagePanel)sender;
TreeNode movedNode;
_mouseDownSelectedWindow = Rectangle.Empty;
if (e.Data.GetDataPresent(testtype))
{
movedNode= (TreeNode)e.Data.GetData(testType);
dropPicturePanel.Tag = movedNode.Tag;
movedNode.ImageIndex = 1;
movedNode.SelectedImageIndex = 1;
movedNode.ForeColor = Color.Gray;
//**************************************
//HERE IS THE CODE FOR THE CREATED PANEL
Panel panel1 = new Panel();
Point point1 = this.PointToClient(new Point(e.X - 278, e.Y - 19)); //the imagePanel1 is on the form at the point 278,19
panel1.AllowDrop = true;
panel1.Location = point1;
panel1.BackgroundImage = iltest.Images[0]; //nvm
panel1.Height = 16;
panel1.Width = 16;
imagePanel1.Controls.Add(panel1); //am adding it to the imagePanel1
//saving the locations of each panel
string path = @"C:\Users\Cosic\Desktop\ICR\TABELA3_Paneli.txt"; // path to file
if (!File.Exists(path))
File.Create(path);
if (panelBr == 0)
System.IO.File.WriteAllBytes(path, new byte[0]); //brise ceo text iz fajla
TextWriter sw = new StreamWriter(path, true);
sw.WriteLine(e.X + "; " + e.Y + "; " + panel1.Width + "; " + panel1.Height + ";");
sw.Close();
//am done with saving
panelBr++;//nvm
}
}告诉我,如果你需要更多的代码…我有很多;)和抱歉,糟糕的英语,没有那么好,我想成为…
发布于 2015-06-09 17:59:55
我解决了问题,就像这样:
panel1.MouseUp += new MouseEventHandler(panel1_MouseUp); 只需编写panel1.anyEventUWant +=和2次制表符按钮...它自动生成一个新函数,其中只有一行代码
下面是一个例子
void panel1_MouseUp (object sender, EventArgs e)
{
//throw new NotImplementedException();
} 你可以像这样访问面板:((object)sender)。
https://stackoverflow.com/questions/30464864
复制相似问题