• <i id='QsFSp'><tr id='QsFSp'><dt id='QsFSp'><q id='QsFSp'><span id='QsFSp'><b id='QsFSp'><form id='QsFSp'><ins id='QsFSp'></ins><ul id='QsFSp'></ul><sub id='QsFSp'></sub></form><legend id='QsFSp'></legend><bdo id='QsFSp'><pre id='QsFSp'><center id='QsFSp'></center></pre></bdo></b><th id='QsFSp'></th></span></q></dt></tr></i><div id='QsFSp'><tfoot id='QsFSp'></tfoot><dl id='QsFSp'><fieldset id='QsFSp'></fieldset></dl></div>
    <tfoot id='QsFSp'></tfoot>
  • <small id='QsFSp'></small><noframes id='QsFSp'>

      • <bdo id='QsFSp'></bdo><ul id='QsFSp'></ul>

      1. <legend id='QsFSp'><style id='QsFSp'><dir id='QsFSp'><q id='QsFSp'></q></dir></style></legend>

        C# 从一个图片框拖放到另一个图片框

        时间:2023-08-25

          <tbody id='toyqx'></tbody>

              <bdo id='toyqx'></bdo><ul id='toyqx'></ul>

                <tfoot id='toyqx'></tfoot>

                  <small id='toyqx'></small><noframes id='toyqx'>

                1. <i id='toyqx'><tr id='toyqx'><dt id='toyqx'><q id='toyqx'><span id='toyqx'><b id='toyqx'><form id='toyqx'><ins id='toyqx'></ins><ul id='toyqx'></ul><sub id='toyqx'></sub></form><legend id='toyqx'></legend><bdo id='toyqx'><pre id='toyqx'><center id='toyqx'></center></pre></bdo></b><th id='toyqx'></th></span></q></dt></tr></i><div id='toyqx'><tfoot id='toyqx'></tfoot><dl id='toyqx'><fieldset id='toyqx'></fieldset></dl></div>
                  <legend id='toyqx'><style id='toyqx'><dir id='toyqx'><q id='toyqx'></q></dir></style></legend>

                2. 本文介绍了C# 从一个图片框拖放到另一个图片框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在使用 C# 在 Visual Studio 2012 中工作,我需要将一个图片框拖动到另一个图片框,基本上用拖动的图片框图像替换目标图片框图像.

                  I'm working in visual studio 2012 with C# and I need to Drag a Picture box into another picture box, basically replace the target Picturebox Image with the Dragged Picture box image.

                  我该怎么做?

                  请具体说明,并尽量以最简单和最好的方式进行解释.我对编程非常陌生,有点绝望,所以请耐心等待.

                  Please be specific and try to explain as simplest and as best as possible. I'm extremely new to programming, and a bit desperate so please be patient with me.

                  推荐答案

                  在 PictureBox 控件上隐藏了拖放.不知道为什么,它工作得很好.这里可能的指导是,对于用户来说,您可以将图像放在控件上并不明显.您必须对此做一些事情,至少将 BackColor 属性设置为非默认值,以便用户可以看到它.

                  Drag+drop is hidden on the PictureBox control. Not sure why, it works just fine. The probable guidance here is that it will not be obvious to the user that you could drop an image on the control. You'll have to do something about that, at least set the BackColor property to a non-default value so the user can see it.

                  无论如何,您需要在第一个图片框上实现 MouseDown 事件,以便您可以单击它并开始拖动:

                  Anyhoo, you'll need to implement the MouseDown event on the first picturebox so you can click it and start dragging:

                      private void pictureBox1_MouseDown(object sender, MouseEventArgs e) {
                          var img = pictureBox1.Image;
                          if (img == null) return;
                          if (DoDragDrop(img, DragDropEffects.Move) == DragDropEffects.Move) {
                              pictureBox1.Image = null;
                          }
                      }
                  

                  我假设您想移动图像,如果需要复制,则在必要时进行调整.然后你必须在第二个图片框上实现 DragEnter 和 DragDrop 事件.由于属性是隐藏的,您应该在表单的构造函数中设置它们.像这样:

                  I assumed you wanted to move the image, tweak if necessary if copying was intended. Then you'll have to implement the DragEnter and DragDrop events on the second picturebox. Since the properties are hidden, you should set them in the form's constructor. Like this:

                      public Form1() {
                          InitializeComponent();
                          pictureBox1.MouseDown += pictureBox1_MouseDown;
                          pictureBox2.AllowDrop = true;
                          pictureBox2.DragEnter += pictureBox2_DragEnter;
                          pictureBox2.DragDrop += pictureBox2_DragDrop;
                      }
                  
                      void pictureBox2_DragEnter(object sender, DragEventArgs e) {
                          if (e.Data.GetDataPresent(DataFormats.Bitmap))
                              e.Effect = DragDropEffects.Move;
                      }
                  
                      void pictureBox2_DragDrop(object sender, DragEventArgs e) {
                          var bmp = (Bitmap)e.Data.GetData(DataFormats.Bitmap);
                          pictureBox2.Image = bmp;
                      }
                  

                  这确实允许您将图像从另一个应用程序拖到框中.让我们称之为功能.如果您想禁止这样做,请使用 bool 标志.

                  This does allow you to drag an image from another application into the box. Let's call it a feature. Use a bool flag if you want to disallow this.

                  这篇关于C# 从一个图片框拖放到另一个图片框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:在 C# 中的面板上拖放时移动控件 下一篇:如何使用filegroupdescriptor将文件拖到资源管理器

                  相关文章

                  最新文章

                3. <small id='6ybEv'></small><noframes id='6ybEv'>

                    <tfoot id='6ybEv'></tfoot>

                      <legend id='6ybEv'><style id='6ybEv'><dir id='6ybEv'><q id='6ybEv'></q></dir></style></legend>
                      <i id='6ybEv'><tr id='6ybEv'><dt id='6ybEv'><q id='6ybEv'><span id='6ybEv'><b id='6ybEv'><form id='6ybEv'><ins id='6ybEv'></ins><ul id='6ybEv'></ul><sub id='6ybEv'></sub></form><legend id='6ybEv'></legend><bdo id='6ybEv'><pre id='6ybEv'><center id='6ybEv'></center></pre></bdo></b><th id='6ybEv'></th></span></q></dt></tr></i><div id='6ybEv'><tfoot id='6ybEv'></tfoot><dl id='6ybEv'><fieldset id='6ybEv'></fieldset></dl></div>
                        <bdo id='6ybEv'></bdo><ul id='6ybEv'></ul>