在这个listbox的双剑事件里面写
System.Diagnostics.Process.Start("C:\Program Files\Windows NT\Accessories\wordpad.exe","你的文件路径");

解决方案 »

  1.   

    this.listBox1.SelectedItem.ToString();是你的文件名称
    但是你不要忘记加上路径
      

  2.   

    那我要是打開一個.bmp文件呢?我也希望能夠支持許多文件,難到我必須要知道這些文件是由哪些程序生成的。有沒有更簡單的方法?
      

  3.   

    brightheroes(闭关|那一剑的风情) 说的方法我觉得以及很简单了
    事实上,Process.Start会根据你提供的filename自动去找到文件关联,找到需要打开该文件的程序,txt也好,bmp也好,如果你非要用指定的程序打开,那就要在start方法中指定程序路径。我觉得楼主有一个问题忽略了,你要的是双击listbox中每一项,实际上listbox并没有提供这个事件,你该怎么办?:)
      

  4.   

    不过还真没有注意过System.Diagnostics.Process.Start的重载3方法:)
      

  5.   

    按楼主和 brightheroes(闭关|那一剑的风情)思路写的,双击选中项就启动程序namespace lei198203
    {
    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;
    using System.Diagnostics;
    /// <summary>
    /// Form1 的摘要说明。
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
    private System.Windows.Forms.ListBox listBox1;
    private Point mousePnt=Point.Empty;
    /// <summary>
    /// 必需的设计器变量。
    /// </summary>
    private System.ComponentModel.Container components = null; public Form1()
    {
    //
    // Windows 窗体设计器支持所必需的
    //
    InitializeComponent(); //
    // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
    //
    } /// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if (components != null) 
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    } #region Windows Form Designer generated code
    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    this.listBox1 = new System.Windows.Forms.ListBox();
    this.SuspendLayout();
    // 
    // listBox1
    // 
    this.listBox1.ItemHeight = 12;
    this.listBox1.Items.AddRange(new object[] {
      "d:\\lei198203.txt ",
      "d:\\U738P28T3D506436F328DT20040916140536.jpg"});
    this.listBox1.Location = new System.Drawing.Point(0, 8);
    this.listBox1.Name = "listBox1";
    this.listBox1.Size = new System.Drawing.Size(288, 184);
    this.listBox1.TabIndex = 0;
    this.listBox1.DoubleClick += new System.EventHandler(this.listBox1_DoubleClick);
    this.listBox1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.listBox1_MouseUp);
    // 
    // Form1
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.ClientSize = new System.Drawing.Size(292, 266);
    this.Controls.AddRange(new System.Windows.Forms.Control[] {
      this.listBox1});
    this.MaximizeBox = false;
    this.Name = "Form1";
    this.Text = "Form1";
    this.ResumeLayout(false); }
    #endregion /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main() 
    {
    Application.Run(new Form1());
    } private void listBox1_DoubleClick(object sender, System.EventArgs e)
    {
    string path=listBox1.SelectedItem as string;
    if(path==null||path.Length==0)
    return;
    int index=listBox1.SelectedIndex;
    int height=listBox1.ItemHeight;

    if(height*index<mousePnt.Y&&height*(index+1)>mousePnt.Y)
        Process.Start(path);

    } private void listBox1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
    {
    this.mousePnt=new Point(e.X,e.Y);
    }

    }
    }
      

  6.   

    非常感謝大家的支持,感謝 brightheroes(闭关|那一剑的风情) 和 micropentium6(小笨|想学ASP) 提供的代碼。