首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何让我的面板移动?

问如何让我的面板移动?
EN

Stack Overflow用户
提问于 2015-05-27 01:11:05
回答 1查看 140关注 0票数 0

怎么回事,我有一个叫做imagePanel1的imagePanel (你可以把它看作一个picturePanel) (我把它导入了,这样我就不用做滚动条了:)

我在左边有一个treeView,我可以从witch拖动一个节点,并将其放到imagePanel上,在那里我可以获得拖放的位置,在这个位置上,我创建了一个名为panel1的普通面板,所以我做了100次,所以在最后我会有一个充满小面板的imagePanel…现在的问题是,当我单击imagePanel (面板所在的位置)时,我希望在MousePress上选择该面板,在mouseMove上移动该面板,在btnDelete上删除eventualLy……

下面是//***********************************************************************的imagePanel代码:

代码语言:javascript
复制
    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

        }
    }

告诉我,如果你需要更多的代码…我有很多;)和抱歉,糟糕的英语,没有那么好,我想成为…

EN

回答 1

Stack Overflow用户

发布于 2015-06-09 17:59:55

我解决了问题,就像这样:

代码语言:javascript
复制
panel1.MouseUp += new MouseEventHandler(panel1_MouseUp); 

只需编写panel1.anyEventUWant +=和2次制表符按钮...它自动生成一个新函数,其中只有一行代码

下面是一个例子

代码语言:javascript
复制
void panel1_MouseUp (object sender, EventArgs e)                  
{         
    //throw new NotImplementedException();     
} 

你可以像这样访问面板:((object)sender)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30464864

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档