简体   繁体   English

使用notepad.exe在列表视图中打开活动项目

[英]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.

相关问题 用新的替换notepad.exe - Replacing notepad.exe with a new one 以Notepad.exe的方式打开文件的标志是什么? - Which flags to open a file the way Notepad.exe does? 使用Awesomium从html按钮运行notepad.exe - Run notepad.exe from a html-button using Awesomium 如何在Windows应用程序中以隐藏模式启动notepad.exe? - How to start notepad.exe in hidden mode in windows application? C# 为什么 Process.Start("notepad.exe" myFile) 正常工作,而 Process.Start("notepad++.exe" myFile) 不工作 - C# Why does Process.Start("notepad.exe" myFile) is working and Process.Start("notepad++.exe" myFile) is not working System.Diagnostics.Process.Start(“ Notepad.exe”); 在实时服务器上不工作 - System.Diagnostics.Process.Start(“Notepad.exe”); is not working on live server Process.Start with UseShellExecute 在前一个关闭窗口后无法将 notepad.exe 窗口带到前台 - Process.Start with UseShellExecute fails to bring notepad.exe window to the foreground after a previous close window 如何获取notepad.exe的确切路径以便关联文件扩展名 - How to get the exact path of notepad.exe in order to associate a file extension 如何在 C# windows 应用程序的表单加载事件中的 process.start("notepad.exe") 之前播放 windows 媒体播放器 - how to play windows media player before the process.start("notepad.exe") in form load event in C# windows app 如何获取右键单击打开上下文菜单之前的ListView项 - How to get the ListView Item that was right clicked before opening the context menu
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM