My starting point is that I have a Side Panel in my MainWindow, in this Panel are my Buttons with my formatting Comand. which looks like that:
<Button Tag="{DynamicResource Add}" Command="IncreaseFontSize" ToolTip="Größer" Content=" Fett" Style="{StaticResource ButtonStyle}"
Background="Transparent" Foreground="Gray" HorizontalAlignment="Center" Width="240" />
And beside the Panel I have an Frame in which I open my Pages. These Pages has RichTextBoxes in it. After I made the text Bold I want to print it. But I only get the Text without the formatting.
What I have tried:
With my Print Button click on my MainWindow there comes this Code:
string richText = new TextRange((PagesNavigation.Content as A4Page).rtb0.Document.ContentStart, (PagesNavigation.Content as A4Page).rtb0.Document.ContentEnd).Text;
string richText2 = new TextRange((PagesNavigation.Content as A4Page).rtb1.Document.ContentStart, (PagesNavigation.Content as A4Page).rtb1.Document.ContentEnd).Text;
string richText3 = new TextRange((PagesNavigation.Content as A4Page).rtb2.Document.ContentStart, (PagesNavigation.Content as A4Page).rtb2.Document.ContentEnd).Text;
string richText4 = new TextRange((PagesNavigation.Content as A4Page).rtb3.Document.ContentStart, (PagesNavigation.Content as A4Page).rtb3.Document.ContentEnd).Text;
if (richText != "")
vm.TextBox1 = richText;
if (richText2 != "")
vm.TextBox2 = richText2;
if (richText3 != "")
vm.TextBox3 = richText3;
if (richText4 != "")
vm.TextBox4 = richText4;
window.ShowDialog();
A4Page is here the name of my Page which I want to Print. After that I open an little Print dialog. I have there an another Print button which looks like that:
A4Page page = new A4Page();
var vm = (ViewModel)this.DataContext;
if (inputQuantity.Text == "0")
MessageBox.Show("Der wert darf nicht 0 sein!!");
else if (vm.selected_printer == null)
MessageBox.Show("Bitt Geben Sie einen Drucker an!!");
else if (vm.selected_printer != null && inputQuantity.Text != "0")
page.print();
And thats opening my Page in which is an Print method where I want to print my Page.
var vm = (ViewModel)this.DataContext;
vm.printcontrol = true;
PrintDialog printDlg = new PrintDialog();
printDlg.PrintQueue = new PrintQueue(new PrintServer(), vm.selected_printer);
printDlg.PrintTicket.CopyCount = vm.PrintCount;
PageMediaSize pageSize = new PageMediaSize(PageMediaSizeName.NorthAmericaLetter);
rtb0.Document.Blocks.Clear();
rtb0.Document.Blocks.Add(new Paragraph(new Run(vm.TextBox1)));
rtb1.Document.Blocks.Clear();
rtb1.Document.Blocks.Add(new Paragraph(new Run(vm.TextBox2)));
rtb2.Document.Blocks.Clear();
rtb2.Document.Blocks.Add(new Paragraph(new Run(vm.TextBox3)));
rtb3.Document.Blocks.Clear();
rtb3.Document.Blocks.Add(new Paragraph(new Run(vm.TextBox4)));
printDlg.PrintTicket.PageMediaSize = pageSize; printDlg.PrintTicket.PageOrientation = PageOrientation.Portrait;
printDlg.PrintVisual(previewprint, "Border Printing.");
vm.printcontrol = false;
So the Text in the Preview where the User can type in Data would look like that:
Test
but the text would look like this in the Print output:
Test
without any Formatting