使用C# Start()
今天終於稍微有一點點時間可以寫BLOG了,腦袋沒甚麼靈感,分享一下一個方便的小技巧。
使用的是Process.Start method,開發工具Visual C# 2008
參考網址: http://msdn.microsoft.com/zh-tw/library/system.diagnostics.process.start.aspx
先開啟一個基本專案,拉出三個button隨意擺設,程式碼如下:
01
using System;
02
using System.Collections.Generic;
03
using System.ComponentModel;
04
using System.Data;
05
using System.Drawing;
06
using System.Linq;
07
using System.Text;
08
using System.Windows.Forms;
09
10
namespace WindowsFormsApplication1
11
{
12
public partial class Form1 : Form
13
{
14
public Form1()
15
{
16
InitializeComponent();
17
}
18
private void button2_Click(object sender, EventArgs e)
19
{
20
// 開啟目標圖片於預設viewer
21
System.Diagnostics.Process.Start(@"c:\A123.jpg");
22
}
23
24
private void button1_Click_1(object sender, EventArgs e)
25
{
26
// 開啟txt檔於預設word editor
27
System.Diagnostics.Process.Start(@"c:\testfile.txt");
28
29
}
30
31
private void button3_Click_1(object sender, EventArgs e)
32
{
33
// 開啟網址於預設瀏覽器
34
System.Diagnostics.Process.Start("http://www.google.com.tw/");
35
36
}
37
}
38
}

02

03

04

05

06

07

08

09

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

是不是很簡單呢?
這樣一來,如果你手頭上有很多要維護的網站,就可以把一些工作常用網址,常用文件,寫起來放進應用程式打包,
以後上班點擊開啟也方便好管理。
|