實現瀏覽

 今天學習了使用SortedList,Hashtable來實現瀏覽的功能
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Diagnostics;

namespace dakaiwenjian
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
SortedList list = new SortedList();
Hashtable hash = new Hashtable();

private void button1_Click(object sender, EventArgs e)
{

if (this.openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
string str = this.openFileDialog1.FileName;
string ext = System.IO.Path.GetExtension(str).ToLower();
string exe = hash[ext].ToString();
Process.Start(exe, str);
}
//if (this.openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
//{
// string str= this.openFileDialog1.FileName;
// string ext = System.IO.Path.GetExtension(str).ToLower();
// string exe = list[ext].ToString();
// Process.Start(exe,str);
//}
}
private void Form1_Load(object sender, EventArgs e)
{
hash.Add(".txt", "notepad.exe");
hash.Add(".jpg", "mspaint.exe");
hash.Add(".bmp", "mspaint.exe");
hash.Add(".doc", "winword.exe");
hash.Add(".xls", "excel.exe");


//list.Add(".txt", "notepad.exe");
//list.Add(".jpg", "mspaint.exe");
//list.Add(".bmp", "mspaint.exe");
//list.Add(".doc", "winword.exe");
//list.Add(".xls", "excel.exe");

}
}
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章