0

我想知道是否有人知道如何使用按钮在记事本中打开活动(突出显示)项目

我现在有这个(笑我。)

Process.Start("notepad.exe", listView1.ItemActivate);

显然这不起作用,有人知道该怎么做吗:x

http://pastie.org/3241590来源供人们大声笑@

4

3 回答 3

1

ItemActivate实际上是一个事件。您将需要处理该事件并将Process.Start代码放在那里。

就像是:

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), ...);
}
于 2012-01-24T05:05:11.107 回答
0

将 ListViewItem 的标记设置为已满文件

 FItems.Tag = fileFullPath;

然后你可以使用标签打开文件

 Process.Start("notepad.exe", listView1.SelectedItems[0].Tag.ToString());

在您的代码更新如下

 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!!");
            }

        }

和点击事件如下

   private void button9_Click(object sender, EventArgs e)
    {
        Process.Start("notepad.exe", listView1.SelectedItems[0].Tag.ToString()); 
    }
于 2012-01-24T05:20:59.383 回答
-1

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"); 
于 2012-01-24T07:29:14.577 回答