<bdo id='VkrK7'></bdo><ul id='VkrK7'></ul>
  • <tfoot id='VkrK7'></tfoot>

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

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

      1. 文件拖放在列表框上不起作用

        时间:2023-08-25
        <legend id='Hk50p'><style id='Hk50p'><dir id='Hk50p'><q id='Hk50p'></q></dir></style></legend>

        1. <tfoot id='Hk50p'></tfoot>
          • <bdo id='Hk50p'></bdo><ul id='Hk50p'></ul>

              <tbody id='Hk50p'></tbody>

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

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

                1. 本文介绍了文件拖放在列表框上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  这是我第一次使用拖放.所以我有一个带有 listbox 的表单,仅此而已.我希望能够将文件从桌面或 Windows 资源管理器拖放到我的列表框中.这是我的代码.缺少什么?

                  This is the first time I am working with drag and drop. So I have a form with a listbox and nothing else. I would like to be able to drag and drop files from desktop or windows explorer into my listbox. This is my code. What is missing?

                  表格:

                   public partial class Form1 : Form
                      {
                          public Form1()
                          {
                              InitializeComponent();
                          }
                  
                          private void listBox1_DragEnter(object sender, DragEventArgs e)
                          {
                              if (e.Data.GetDataPresent(DataFormats.FileDrop))
                                  e.Effect = DragDropEffects.All;
                              else
                                  e.Effect = DragDropEffects.None;
                          }
                  
                  
                          private void listBox1_DragDrop(object sender, DragEventArgs e)
                          {
                              string[] s = (string[])e.Data.GetData(DataFormats.FileDrop, false);
                              int i;
                              for (i = 0; i < s.Length; i++)
                                  listBox1.Items.Add(s[i]);
                          }
                      }
                  

                  Form1.Designer.cs:(初始化组件)

                  private void InitializeComponent()
                  {
                      this.listBox1 = new System.Windows.Forms.ListBox();
                      this.SuspendLayout();
                      // 
                      // listBox1
                      // 
                      this.listBox1.AllowDrop = true;
                      this.listBox1.FormattingEnabled = true;
                      this.listBox1.Location = new System.Drawing.Point(30, 23);
                      this.listBox1.Name = "listBox1";
                      this.listBox1.Size = new System.Drawing.Size(376, 238);
                      this.listBox1.TabIndex = 0;
                      this.listBox1.DragDrop += new System.Windows.Forms.DragEventHandler(this.listBox1_DragDrop);
                      this.listBox1.DragEnter += new System.Windows.Forms.DragEventHandler(this.listBox1_DragEnter);
                      this.listBox1.DragOver += new System.Windows.Forms.DragEventHandler(this.listBox1_DragOver);
                      // 
                      // Form1
                      // 
                      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
                      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                      this.ClientSize = new System.Drawing.Size(438, 366);
                      this.Controls.Add(this.listBox1);
                      this.Name = "Form1";
                      this.Text = "Form1";
                      this.ResumeLayout(false);
                  }
                  

                  推荐答案

                  我做了这个,我想这样就可以了.而且不需要 DragOver.

                  I make this and i think this will be OK.And no need DragOver.

                      private void listBox_DragEnter(object sender, DragEventArgs e)
                      {
                          if (e.Data.GetDataPresent(DataFormats.FileDrop))
                              e.Effect = DragDropEffects.All;
                          else
                              e.Effect = DragDropEffects.None;
                      }
                  
                      private void listBox_DragDrop(object sender, DragEventArgs e)
                      {
                          if (listBox.Items.Count != 0)
                          {
                              listBox.Items.Clear();
                          }
                          string[] s = (string[])e.Data.GetData(DataFormats.FileDrop, false);
                          int i;
                          for (i = 0; i < s.Length; i++)
                              listBox.Items.Add(Path.GetFileName(s[i]));
                      }
                  

                  这篇关于文件拖放在列表框上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:将大型虚拟文件从 C# 拖放到 Windows 资源管理器 下一篇:使用 Selenium 和 C# 在 draggable=true 时拖放不工作

                  相关文章

                  最新文章

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

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

                    1. <small id='6CDdM'></small><noframes id='6CDdM'>

                        <bdo id='6CDdM'></bdo><ul id='6CDdM'></ul>