菜鸟提问:谁可以告诉我,怎么在listbox显示的文件信息中点右键添加删除选项using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using ClassLibrary1;namespace WindowsApplication7
{
public partial class fmMain : Form
{
private string _savePath;
public fmMain()
{
InitializeComponent();
}
private void bnSearch_Click(object sender, EventArgs e)
{
SearchDIR result = new SearchDIR();
result.path = "c:\\1";
_savePath = result.GetPath();
} private void button1_Click_1(object sender, EventArgs e)
{
char[] charSeparatory = new char[] { '|' };
string[] resultPath;
resultPath = _savePath.Split(charSeparatory, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < resultPath.Length; i++)
{
listBox1.Items.Add(resultPath[i]);
}
}
private void listBox1_DoubleClick(object sender, EventArgs e)
{
if (listBox1.SelectedItem != null)
{
string curItem = listBox1.SelectedItem.ToString();
int j = curItem.LastIndexOf('\\');
string text = curItem.Remove(j);
System.Diagnostics.Process.Start("explorer.exe", text);
}
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using ClassLibrary1;namespace WindowsApplication7
{
public partial class fmMain : Form
{
private string _savePath;
public fmMain()
{
InitializeComponent();
}
private void bnSearch_Click(object sender, EventArgs e)
{
SearchDIR result = new SearchDIR();
result.path = "c:\\1";
_savePath = result.GetPath();
} private void button1_Click_1(object sender, EventArgs e)
{
char[] charSeparatory = new char[] { '|' };
string[] resultPath;
resultPath = _savePath.Split(charSeparatory, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < resultPath.Length; i++)
{
listBox1.Items.Add(resultPath[i]);
}
}
private void listBox1_DoubleClick(object sender, EventArgs e)
{
if (listBox1.SelectedItem != null)
{
string curItem = listBox1.SelectedItem.ToString();
int j = curItem.LastIndexOf('\\');
string text = curItem.Remove(j);
System.Diagnostics.Process.Start("explorer.exe", text);
}
}
}
}
在工具箱里
拖近来
添加菜单。
然把设置Listbox的contextMenuStrip属性
如果你已经拖近来了contextMenuStrip
那么哪个属性能选择...