public DocumentPaginator GetPaginator(double pageWidth, double pageHeight) { TextRange originalRange = new TextRange(_textBox.Document.ContentStart, _textBox.Document.ContentEnd); MemoryStream memoryStream = new MemoryStream(); originalRange.Save(memoryStream, DataFormats.Xaml); FlowDocument copy = new FlowDocument(); TextRange copyRange = new TextRange(copy.ContentStart, copy.ContentEnd); copyRange.Load(memoryStream, DataFormats.Xaml); DocumentPaginator paginator = ((IDocumentPaginatorSource)copy).DocumentPaginator; return(new PrintingPaginator(paginator, new Size(pageWidth, pageHeight), new Size(96, 96))); }
public bool OpenDocument() { OpenFileDialog dlg = new OpenFileDialog(); if (dlg.ShowDialog() == true) { _currentFile = dlg.FileName; using (Stream stream = dlg.OpenFile()) { TextRange range = new TextRange( _textBox.Document.ContentStart, _textBox.Document.ContentEnd ); range.Load(stream, DataFormats.Rtf); } return(true); } return(false); }
public bool OpenDocument() { OpenFileDialog dig = new OpenFileDialog(); dig.Filter = "All Text Documents (.rtf, .txt)|*.rtf; *.txt|Text Documents (.rtf)|*.rtf|Text Files (.txt)|*.txt|All Files (*.*)|*.*"; if (dig.ShowDialog() == true) { this._currentFile = dig.FileName; using (Stream stream = dig.OpenFile()) { TextRange range = new TextRange(_textBox.Document.ContentStart, _textBox.Document.ContentEnd); range.Load(stream, DataFormats.Rtf); } return(true); } return(false); }
private void OpenFile() { try { OpenFileDialog openFileDialog = new OpenFileDialog { FileName = "text.txt", InitialDirectory = @"D:\" }; openFileDialog.Multiselect = true; openFileDialog.Filter = "Text files (*.txt)|*.txt|Rich text files (*.rtf)|*.rtf|XAML files (*.xaml)|*.xaml|All files (*.*)|*.*"; if (openFileDialog.ShowDialog() == true) { TabItem tabItem = new TabItem(); tabItem.Header = openFileDialog.FileName; RichTextBox richTextBox = new RichTextBox(); tabItem.Content = richTextBox; tabItem.AllowDrop = true; TextRange textRange = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd); using (FileStream fs = new FileStream(openFileDialog.FileName, FileMode.Open)) { switch (System.IO.Path.GetExtension(openFileDialog.FileName).ToLower()) { case ".rtf": textRange.Load(fs, DataFormats.Rtf); break; case ".txt": textRange.Load(fs, DataFormats.Text); break; default: textRange.Load(fs, DataFormats.Xaml); break; } } RefreshRecentFilesList(openFileDialog.FileName); RefreshRecentFilesListInMenu(); if (count < 10) { if (this.count == 0) { Tab_Control.Items[count] = tabItem; } else { Tab_Control.Items.Add(tabItem); } Tab_Control.SelectedIndex = count++; } else { MessageBox.Show("Превышено максимально кол-во вкладок"); } this.Title = "Text Editor (" + openFileDialog.FileName + ") "; } } catch (Exception e) { MessageBox.Show(e.Message + " Open error"); } }