예제 #1
0
        private void RichTextBox_Drop(object sender, DragEventArgs e)
        {
            RichTextBox currentRichTextBox = TabItemManipulate.GetCurrentRichTextBox(_ControlBox);

            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                string[] docPath = (string[])e.Data.GetData(DataFormats.FileDrop);

                var dataFormat = DataFormats.Text;


                System.Windows.Documents.TextRange range;
                System.IO.FileStream fStream;
                if (System.IO.File.Exists(docPath[0]))
                {
                    try
                    {
                        // Open the document in the RichTextBox.
                        range   = new System.Windows.Documents.TextRange(currentRichTextBox.Document.ContentStart, currentRichTextBox.Document.ContentEnd);
                        fStream = new System.IO.FileStream(docPath[0], System.IO.FileMode.OpenOrCreate);
                        range.Load(fStream, dataFormat);
                        fStream.Close();
                    }
                    catch (System.Exception)
                    {
                        //MessageBox.Show("File could not be opened. Make sure the file is a text file.");
                    }
                }
            }
        }
예제 #2
0
        private void CommandBinding_Save(object sender, ExecutedRoutedEventArgs e)
        {
            RichTextBox LehaGdeBruski = new RichTextBox();

            LehaGdeBruski.TextChanged += new TextChangedEventHandler(RichTextBox_TextChanged);

            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.Filter = "Text file|.txt";
            saveFileDialog.Title  = "Save text file";

            if (saveFileDialog.ShowDialog() == true)
            {
                RichTextBox currentRichText = TabItemManipulate.GetCurrentRichTextBox(_ControlBox);

                string myText = new TextRange(currentRichText.Document.ContentStart, currentRichText.Document.ContentEnd).Text;
                System.IO.File.WriteAllText(saveFileDialog.FileName, myText);
                MessageBox.Show("Файл сохранен");
            }
        }
예제 #3
0
        //private void ClrPcker_Background_OnSelectedColorChanged(object sender, RoutedPropertyChangedEventArgs<Color?> e)
        //{
        //    if (_ControlBox != null)
        //    {
        //        TabItem tab = _ControlBox.SelectedItem as TabItem;
        //        RichTextBox RtextBox = tab.Content as RichTextBox;
        //        Color? C = ClrPcker_Background.SelectedColor.Value as Color?;
        //        RtextBox.Selection.ApplyPropertyValue(Inline.ForegroundProperty, Brush.C);
        //    }
        //}
        private void CommandBinding_Open(object sender, ExecutedRoutedEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = "Text file| *.txt";
            openFileDialog.Title  = "Open text file";

            RichTextBox richTextBox = RichTExtBoxCreatetor.CreateRichTextBox(item_Click_Close,
                                                                             RichTextBox_DragOver,
                                                                             RichTextBox_Drop,
                                                                             RichTextBox_TextChanged
                                                                             );

            if (openFileDialog.ShowDialog() == true)
            {
                TabItemManipulate.NewTabItem(openFileDialog.FileName, richTextBox, _ControlBox);

                RichTextBox currentRichTextBox = TabItemManipulate.GetCurrentRichTextBox(_ControlBox);

                currentRichTextBox.Selection.Text = File.ReadAllText(openFileDialog.FileName);

                LastFileSaver.AddFilePath(openFileDialog.FileName);
            }
        }