【问题标题】:How to make my panel move?如何让我的面板移动?
【发布时间】:2015-05-26 17:11:04
【问题描述】:

有什么关系,我有一个 imagePanel(你可以把它看成一个 picturePanel) 称为imagePanel1(我导入了它,所以我不必制作滚动条:))

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

下面是 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

        }
    }

如果您需要更多代码,请告诉我...我有很多;) 对不起,英语不好,没有我想的那么好......

【问题讨论】:

  • 有没有办法附上你的 GUI 截图?其他人可能会理解,但我很难在脑海中想象你的 GUI。
  • sry 标题...但我不能发布图片,我需要 10 个 repurtations 才能做到这一点...这是描述:在左角是一个名为 tView 的树视图,在右上角是名为 imagePanel1 的 imagePanel,还有一个背景更改按钮和一个退出按钮,仅此而已

标签: c# select panel move picturebox


【解决方案1】:

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

panel1.MouseUp += new MouseEventHandler(panel1_MouseUp); 

只需编写 panel1.anyEventUWant += 和 2 次选项卡按钮.... 它会自动生成一个新函数,其中包含一个代码行

这是一个例子

void panel1_MouseUp (object sender, EventArgs e)                  
{         
    //throw new NotImplementedException();     
} 

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-15
    • 1970-01-01
    • 2012-11-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多