单击列表框中的项目时如何打开文件 [英] How to open a file on click of item in List Box

查看:72
本文介绍了单击列表框中的项目时如何打开文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在列表框中单击项目时打开一个特定文件..谢谢...

i want to open a particular file on click of item in List box..thanks...

推荐答案

我建​​议您在.

做类似的事情,
I would suggest you to do it on DoubleClick.

Do something like,
switch (ListBox1.SelectedIndex) 
{
	case 0:
		//open file 1
		//Process.Start("notepad");
		break;
	case 1:
		//open file 2
		//Process.Start("calc");
		break;
	default:
		break;
	//do nothing
}


这样做:

正如Prera​​k所说,请在DoubleClick事件中执行以下操作.

将此添加到您的构造函数中:
Do it like this :

As said by Prerak, do the below in a DoubleClick event.

Add this to your constructor :
listBox2.MouseDoubleClick += new MouseButtonEventHandler(listBox2_MouseDoubleClick);


这是实现它的功能:


This is the function to implement it:

void listBox2_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
    ListBoxItem item =(ListBoxItem)listBox2.SelectedItem;
    Process.Start(item.Content.ToString());
}


这篇关于单击列表框中的项目时如何打开文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆