Presentation is loading. Please wait.

Presentation is loading. Please wait.

客製化安裝 建國科技大學 資管系 饒瑞佶.

Similar presentations


Presentation on theme: "客製化安裝 建國科技大學 資管系 饒瑞佶."— Presentation transcript:

1 客製化安裝 建國科技大學 資管系 饒瑞佶

2 首先需要有一個Windows Form專案

3 修改Windows Form專案的App.config檔案
加入以下設定 <appSettings> <add key="FilePath" value="Images\cat.png"/> </appSettings>

4 加入以下語法到Form1表單的建構子中 // 從App.config檔案取得name=FilePath的設定
string filePath = ConfigurationSettings.AppSettings["FilePath"]; // 將圖設定成背景 Image backImage = Image.FromFile(filePath); this.BackgroundImage = backImage.GetThumbnailImage( this.Width, this.Height, null, IntPtr.Zero); this.Refresh();

5 新增安裝專案

6 選擇Setup Project

7

8

9

10 預設安裝過程只有3個步驟 When we run the installation wizard, we see only three screens: Welcome screen, Installation Folder screen (in which we specify were to install our application, and it is in that location that the installation wizard will install all the items we put in the 'Application Folder' node in the 'File System' eindow), and the Confirm screen which is the last screen before the installation finishes.

11 安裝專案中加入View

12 預設安裝過程3個步驟

13 加入文字方塊(A)

14 設定文字方塊頁面上的物件 可以直接拉動調整順序

15 View  自訂動作

16

17 滑鼠左鍵雙擊 滑鼠左鍵雙擊

18 同樣動作在uninstall再做一次 滑鼠左鍵雙擊 滑鼠左鍵雙擊

19

20 專案中加入「安裝程式類別」

21 專案中加入「安裝程式類別」

22 覆寫Install方法 與第19頁設定有關 執行檔安裝位置
public override void Install(System.Collections.IDictionary stateSaver) { base.Install(stateSaver); try // In order to get the value from the textBox named 'EDITA1' I needed to add the line: // '/PathValue = [EDITA1]' to the CustomActionData property of the CustomAction We added. string filesPath = Context.Parameters["PathValue"]; // Get the path to the executable file that is being installed on the target computer string assemblypath = Context.Parameters["assemblypath"]; string appConfigPath = assemblypath + ".config"; // Write the path to the app.config file XmlDocument doc = new XmlDocument(); doc.Load(appConfigPath); 與第19頁設定有關 執行檔安裝位置

23 XmlNode configuration = null;
foreach (XmlNode node in doc.ChildNodes) if (node.Name == "configuration") configuration = node; if (configuration != null) { // Get the 'appSettings' node XmlNode settingNode = null; foreach (XmlNode node in configuration.ChildNodes) if (node.Name == "appSettings") settingNode = node; if (settingNode != null) // Get the node with the attribute key="FilePath" XmlNode NumNode = null; foreach (XmlNode node in settingNode.ChildNodes) if (node.Attributes["key"] != null) if (node.Attributes["key"].Value == "FilePath") NumNode = node; }

24 if (NumNode != null) { XmlAttribute att = NumNode.Attributes["value"]; att.Value = filesPath; // Update the configuration file // Save the configuration file doc.Save(appConfigPath); } catch (FormatException e) string s = e.Message;

25 建置方案

26 result 這裡要給定圖檔路徑 Images\cat.png

27 資料寫入WindowsFormsApplication1.exe.config


Download ppt "客製化安裝 建國科技大學 資管系 饒瑞佶."

Similar presentations


Ads by Google