i am listing files from directories on click on that specific folder name, when files show in datagridview. Now using context menu i want to add this sendto option in that context menu and want to send that file to any removable media.
问问题
2216 次
2 回答
2
您在 Windows 的“发送到”菜单中看到的程序快捷方式存储在%APPDATA%\Microsoft\Windows\SendTo
文件夹中。
阅读此文件夹的内容并在网格的上下文菜单中显示选项。
快捷方式是.LNK
文件。从 LNK 文件中解析 EXE 的名称并使用System.Diagnostics.Process.Run
这是从 LNK 文件中解析 EXE 位置的方法
于 2012-06-22T05:08:25.150 回答
0
尝试修改此示例,它在不同的列上启用不同的选项:
//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 的类似问题:
于 2012-06-22T05:03:57.543 回答