日本好好热aⅴ|国产99视频精品免费观看|日本成人aV在线|久热香蕉国产在线

  • <cite id="ikgdy"><table id="ikgdy"></table></cite>
    1. 西西軟件園多重安全檢測下載網(wǎng)站、值得信賴的軟件下載站!
      軟件
      軟件
      文章
      搜索

      首頁編程開發(fā)C#.NET → C#實現(xiàn)文件拖放并打開文件DragEnter、DragDrop事件

      C#實現(xiàn)文件拖放并打開文件DragEnter、DragDrop事件

      相關軟件相關文章發(fā)表評論 來源:西西整理時間:2012/10/10 11:35:02字體大小:A-A+

      作者:佚名點擊:1132次評論:0次標簽: 文件拖放

      • 類型:文件處理大。209KB語言:中文 評分:7.0
      • 標簽:
      立即下載

      需要知道的ListBox的兩個事件:當您在控件的邊界內(nèi)拖動對象時,便會發(fā)生 DragEnter 事件;該事件用于確

      定當前拖動的對象是不是您要放到控件上的對象。 在將一個或多個文件拖到控件上時,需要處理此事件。 這使

      得在將對象拖到控件上方時,能夠根據(jù)所拖動的對象顯示相應的圖標。 將拖動的對象釋放到控件上時,會發(fā)生

      DragDrop 事件。

      功能描述:向ListBox拖入一個文件,ListBox顯示該文件的路徑,然后單擊該路徑,點擊Open按鈕打開該文件。

      代碼實現(xiàn):

      需要將ListBox的AllowDrop屬性改為true,并實現(xiàn)它的DragEnter、DragDrop這兩個事件。

      using System;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.Data;
      using System.Drawing;
      using System.Linq;
      using System.Text;
      using System.Windows.Forms;

      namespace DragDrop
      {
          public partial class DragDrop : Form
          {
              public string FilePath;

              public DragDrop()
              {
                  InitializeComponent();
              }

              ///


              /// 獲取ListBox的值。
              ///

              ///
              public string GetListBoxItem()
              {
                  string filePath = string.Empty;
                 
                  bool isSelected = IsListBoxSelected();

                  if (isSelected==true)
                  {
                      string listBoxItemValue = lbFilePath.SelectedItem.ToString();

                      filePath = listBoxItemValue;
                  }
                  else
                  {
                      MessageBox.Show("ListBox must be selected.");
                  }

                  return filePath;
              }

              ///
              /// ListBox內(nèi)的值是否被選中。
              ///

              ///
              public bool IsListBoxSelected()
              {
                  bool selected;

                  if (lbFilePath.SelectedIndex == -1)//SelectedIndex==-1時,表示未選中任何項。
                  {
                      selected = false;
                  }
                  else
                  {
                      selected = true;
                  }

                  return selected;
              }

              private void lbFilePath_DragEnter(object sender, DragEventArgs e)
              {
                  if (e.Data.GetDataPresent(DataFormats.FileDrop))
                  {
                      e.Effect = DragDropEffects.All;
                  }
                  else
                  {
                      e.Effect = DragDropEffects.None;
                  }
              }

              private void lbFilePath_DragDrop(object sender, DragEventArgs e)
              {
                  string[] s=(string[])e.Data.GetData(DataFormats.FileDrop,false);
                 
                  for (int i = 0; i < s.Length; i++)
                  {
                      lbFilePath.Items.Add(s[i]);
                  }
              }

              private void btnOpenFile_Click(object sender, EventArgs e)
              {
                  string filePath=GetListBoxItem();

                  if (!string.IsNullOrEmpty(filePath))
                  {
                      System.Diagnostics.Process.Start(filePath);
                  }
              }
          }
      }

      總結:

      Data 對象的 GetData 方法返回一個字符串數(shù)組,該數(shù)組包含拖到該列表框控件中的文件的完整路徑名。 可以使用此文件路徑信息來執(zhí)行需要對文件執(zhí)行的任何操作。

        hosts修復軟件
        (60)hosts修復軟件
        文件是計算機中一個舉足輕重的文件,該文件有一個比較大的特點就是沒有擴展名。經(jīng)常在一些電腦個性技巧以及其他領域方面會用到,西西提供文件修復工具軟件下載大全。官方介紹是一個沒有擴展名的系統(tǒng)文件,可以用記事本等工具打開,其作用就是將一些常用的網(wǎng)址域名與其對應的地址建立一個關聯(lián)數(shù)據(jù)庫,當用戶在瀏覽器中輸入一個需要登錄的網(wǎng)址時,系統(tǒng)會首先自動從文件中尋找對應的地址,一旦找到系統(tǒng)會立即打開對應網(wǎng)頁,如果沒有找...更多>>

        相關評論

        閱讀本文后您有什么感想? 已有人給出評價!

        • 8 喜歡喜歡
        • 3 頂
        • 1 難過難過
        • 5 囧
        • 3 圍觀圍觀
        • 2 無聊無聊

        熱門評論

        最新評論

        發(fā)表評論 查看所有評論(0)

        昵稱:
        表情: 高興 可 汗 我不要 害羞 好 下下下 送花 屎 親親
        字數(shù): 0/500 (您的評論需要經(jīng)過審核才能顯示)