예제 #1
0
        private void startLoad()
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = "txt files (*.txt)|*.txt";

            //From example code. What is FitlerIndex doing exactly? Is 2 wrong
            openFileDialog.FilterIndex      = 2;
            openFileDialog.RestoreDirectory = true;

            if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                textDocument.FilePath = openFileDialog.FileName;
                if (textDocument.Load(textDocument.FilePath))
                {
                    notes_textBox.Text = textDocument.ToString();

                    unsetModifiedState();
                    alreadyBeenSaved = true;
                }
                else
                {
                    System.Windows.Forms.MessageBox.Show("An error occurred loading the document.", "Text Editor", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
예제 #2
0
        private void openButton_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter           = "txt files (*.txt)|*.txt";
            openFileDialog.FilterIndex      = 1;
            openFileDialog.RestoreDirectory = true;

            if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                textBox.Text = "";
                textDocument.Load(openFileDialog.FileName, textBox);
            }
        }
예제 #3
0
        private void MenuItem_Open_Click(object sender, RoutedEventArgs e)
        {
            if (textDocument.isChanged && System.Windows.Forms.MessageBox.Show("Want to save your changes?", "Save changes?", MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult.OK)
            {
                if (textDocument.filePath != null)
                {
                    textDocument.Save(textDocument.filePath, textBox);
                }
                else
                {
                    SaveFileDialog saveFileDialog = new SaveFileDialog();
                    saveFileDialog.Filter           = "txt files (*.txt)|*.txt";
                    saveFileDialog.FilterIndex      = 1;
                    saveFileDialog.RestoreDirectory = true;


                    if (saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        textDocument.Save(saveFileDialog.FileName, textBox);
                    }
                }
                //textBox.Text = "";
                //textDocument.isChanged = false;
            }

            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter           = "txt files (*.txt)|*.txt";
            openFileDialog.FilterIndex      = 1;
            openFileDialog.RestoreDirectory = true;


            if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                textBox.Text = "";
                textDocument.Load(openFileDialog.FileName, textBox);
            }
            textDocument.filePath  = openFileDialog.FileName; //takes note of where the user opened the file from
            textDocument.isChanged = false;                   //loading the file in will trigger the TextChanged event, so I set it to false here so users can exit after loading if nothing has changed
        }