/// <summary> /// Open file of user's choice and read the text file. /// </summary> /// <param name="sender">menu item open</param> /// <param name="e">event of the open menu item clicked</param> private void openMenuItem_Click(object sender, EventArgs e) { #region open file TextOpenFileDialog.Title = "Please Select HTML File"; //the title of the openfiledialog. TextOpenFileDialog.Filter = "Text|*.txt|All|*.*"; if (TextOpenFileDialog.ShowDialog() == DialogResult.OK) //if the file is able to open by pressing ok do the following. Otherwise it was canceled. { fileName = TextOpenFileDialog.FileName; //Assign the file to fileName string. // Open the file for reading purposes Read(); //read text file. //order the doctorWhos by ordinal. doctorWhos = doctorWhos.OrderBy(x => x.ordinal).ToList(); //get ordinal, add to the ordinal to the combobox. foreach (Doctor timeLord in doctorWhos) { doctorComboBox.Items.Add(timeLord.ordinal); } } else { MessageBox.Show("You canceled this operation"); //Cancelling open file. } #endregion }
/// <summary> /// Нажатие кнопки "Открыть файл" для текстовой модели /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OpenTextButton_Click(object sender, EventArgs e) { Debug.WriteLine("OpenTextButton clicked"); if (TextOpenFileDialog.ShowDialog() == DialogResult.OK) { Debug.WriteLine("Dialog result ok"); var text = File.ReadAllText(TextOpenFileDialog.FileName); Debug.WriteLine("----------Got text----------"); Debug.WriteLine(text); Debug.WriteLine("----------------------------"); InputTestRichTextBox.Text = text; } }