[英]Opening active item in a listview with notepad.exe
I was wondering if anybody knew how to open the active (highlighted) item in notepad using a button 我想知道是否有人知道如何使用按钮打开记事本中的活动(突出显示)项目
I've got this right now (laugh at me.) 我现在有这个(嘲笑我)。
Process.Start("notepad.exe", listView1.ItemActivate);
Obviously this doesn't work, does anybody know what to do :x 显然这是行不通的,有人知道该怎么做:x
http://pastie.org/3241590 source for people to lol @ http://pastie.org/3241590人们对大声笑的来源@
ItemActivate
is actually an event. ItemActivate
实际上是一个事件。 You will need to handle that event and place the Process.Start
code in there. 您将需要处理该事件,并将Process.Start
代码放在其中。
Something like: 就像是:
private void listView1_ItemActivate(Object sender, EventArgs e)
{
// You'll want to use index 0 for the first item (or only item) selected.
//
// You'll need to dig down into the SelectedItem to get the string for
// the file to launch.
//
Process.Start("notepad.exe", listView.SelectedItem(0), ...);
}
set tag of ListViewItem as full of file 将ListViewItem的标签设置为文件已满
FItems.Tag = fileFullPath;
then you can open file using tag 然后您可以使用标签打开文件
Process.Start("notepad.exe", listView1.SelectedItems[0].Tag.ToString());
in your code update as below 在您的代码更新如下
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
try
{
TreeNode current = e.Node;
string path = current.FullPath;
string[] Files = Directory.GetFiles(path);
string[] Directories = Directory.GetDirectories(path);
string[] subinfo = new string[3];
listView1.Clear();
listView1.Columns.Add("Name", 255);
listView1.Columns.Add("Size", 100);
listView1.Columns.Add("Type", 80);
foreach (string Dname in Directories)
{
subinfo[0] = GetFileName(Dname);
subinfo[1] = "";
subinfo[2] = "FOLDER";
ListViewItem DItems = new ListViewItem(subinfo);
listView1.Items.Add(DItems);
}
foreach (string Fname in Files)
{
subinfo[0] = GetFileName(Fname);
subinfo[1] = GetSizeinfo(Fname);
subinfo[2] = GetTypeinfo(Fname);
ListViewItem FItems = new ListViewItem(subinfo);
FItems.Tag = Fname; // set the tag here
listView1.Items.Add(FItems);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error!!");
}
}
and Click event as below 然后点击事件如下
private void button9_Click(object sender, EventArgs e)
{
Process.Start("notepad.exe", listView1.SelectedItems[0].Tag.ToString());
}
Try this: 尝试这个:
Code to open notepad with the content in textbox 代码以文本框中的内容打开记事本
Clipboard.SetDataObject(textBox1.Text, true);
Process.Start("notepad");
System.Threading.Thread.Sleep(500);
SendKeys.SendWait("^v");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.