public frmMain() { InitializeComponent(); try { // Set reference to main form frmMainRef = this; // Load user config file objUserConfig.LoadFile("User.config"); // Load setting config file objSettingConfig.LoadFile("Setting.config"); // Generate command structure objStruct.GenerateAllCommand(objSettingConfig.allItems); // Display in GUI // Timer value tbarConnectionTxt.Text = objUserConfig.allItems["OptStepTimer"]; // Loop value tbarLoopTxt.Text = objUserConfig.allItems["OptLoop"]; // List of file foreach (KeyValuePair<string, string> pair in objUserConfig.allItems) { if (pair.Key.Contains("File")) { // Get file name and file path string filePath = pair.Value; string fileName = Path.GetFileName(filePath); // Add to list view ComboboxItem item = new ComboboxItem(); item.FileName = fileName; item.FilePath = filePath; listFile.Items.Add(item); } } } catch (Exception ex) { MessageBox.Show("Error to read config file\nError = " + ex.Message); Application.Exit(); } }
// Handle action: User click Add button private void tbarAdd_Click(object sender, EventArgs e) { // Show Select File Dialog // Create an instance of the open file dialog box. OpenFileDialog openFileDialog1 = new OpenFileDialog(); // Set filter options and filter index. openFileDialog1.Filter = "Scenario Files (.txt)|*.txt|All Files (*.*)|*.*"; openFileDialog1.FilterIndex = 1; openFileDialog1.Multiselect = true; // Call the ShowDialog method to show the dialog box. DialogResult userClickedOK = openFileDialog1.ShowDialog(); // Process input if the user clicked OK. if (userClickedOK == DialogResult.OK) { // Add the files foreach (String path in openFileDialog1.FileNames) { string fileName = Path.GetFileName(path); ComboboxItem item = new ComboboxItem(); item.FileName = fileName; item.FilePath = path; listFile.Items.Add(item); } // Select first items if (listFile.Text == "") { listFile.SelectedIndex = 0; } } }