【问题标题】:How I can use windows's SendTo option in my C# Application using datagridview如何使用 datagridview 在我的 C# 应用程序中使用 windows 的 SendTo 选项
【发布时间】:2012-06-24 09:51:49
【问题描述】:

当文件显示在 datagridview 中时,我会在单击该特定文件夹名称时列出目录中的文件。现在使用上下文菜单,我想在该上下文菜单中添加此 sendto 选项,并希望将该文件发送到任何可移动媒体。

【问题讨论】:

    标签: c# sendto


    【解决方案1】:

    您在 Windows 的“发送至”菜单中看到的程序快捷方式存储在 %APPDATA%\Microsoft\Windows\SendTo 文件夹中。

    阅读此文件夹的内容并在网格的上下文菜单中显示选项。

    快捷方式是.LNK 文件。从LNK文件中解析EXE的名字,调用EXE使用System.Diagnostics.Process.Run

    以下是如何从 LNK 文件中解析 EXE 位置

    http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/8d0f33a3-af4d-498f-a37b-e6fc84136c4a/

    【讨论】:

      【解决方案2】:

      尝试修改这个例子,它在不同的列上启用不同的选项:

      //Define different context menus for different columns
      private ContextMenu contextMenuForColumn1 = new ContextMenu();
      private ContextMenu contextMenuForColumn2 = new ContextMenu();
      
      Add the following line of code in the form load event:
      
      private void Form_Load(object sender, EventArgs e)
      {
          // Load all default values of controls 
          populateDataGridView();
      
          // Add context mneu items
          contextMenuForColumn1.MenuItems.Add("Make Active", new     EventHandler(MakeActive));
          contextMenuForColumn2.MenuItems.Add("Delete", new     EventHandler(Delete));
          contextMenuForColumn2.MenuItems.Add("Register", new     EventHandler(Register));
      }
      
      Add the following code to mouseup event of the gridview:
      
      private void dataGridView_MouseUp(object sender, MouseEventArgs e)
      {
          // Load context menu on right mouse click
          DataGridView.HitTestInfo hitTestInfo;
          if (e.Button == MouseButtons.Right)
          {
              hitTestInfo = dataGridView.HitTest(e.X, e.Y);
              // If column is first column
              if (hitTestInfo.Type == DataGridViewHitTestType.Cell && hitTestInfo.ColumnIndex == 0)
                  contextMenuForColumn1.Show(dataGridView, new Point(e.X, e.Y));
              // If column is second column
              if (hitTestInfo.Type == DataGridViewHitTestType.Cell && hitTestInfo.ColumnIndex == 1)
                  contextMenuForColumn2.Show(dataGridView, new Point(e.X, e.Y));
          }
      } 
      

      关于 SO 的类似问题:

      【讨论】:

      • 实际上我想将文件从网格视图移动到可移动媒体。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-02
      • 2011-01-29
      • 1970-01-01
      • 2016-06-03
      • 2016-09-13
      • 1970-01-01
      相关资源
      最近更新 更多