This is a migrated thread and some comments may be shown as answers.

Print RadRichTextBoxin Invisible Mode

6 Answers 106 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Anthony
Top achievements
Rank 1
Anthony asked on 08 Jul 2011, 08:55 AM
What I'm trying to achieve... I create a RadRichTextBox and set its Visibility to Collapsed.After I add some text and try to print it using

TextArea.Print("test", Telerik.Windows.Documents.UI.PrintMode.Native)

But it throws an exception.

If I set it to Visible before calling Print then it works....Can anybody help me?
 

6 Answers, 1 is accepted

Sort by
0
Anthony
Top achievements
Rank 1
answered on 11 Jul 2011, 08:11 AM
Sorry guy I found where was my problem.But now I'm facing another problem.When I print my RadDocument I wanna use PrintCompleted Event.I use code...


Private m_oTextBox As Telerik.Windows.Controls.RadRichTextBox
 m_oTextBox = New Telerik.Windows.Controls.RadRichTextBox()
 m_oTextBox.Width = 0
 m_oTextBox.Height = 0
 Me.LayoutRoot.Children.Add(m_oTextBox)
 
 
 Try
       m_oTextBox.Document = TextArea.Document
       m_oTextBox.ApplyTemplate()
       m_oTextBox.UpdateEditorLayout()
       m_oTextBox.ActiveEditorPresenter = New Telerik.Windows.Documents.UI.DocumentPrintPresenter(New                                    Telerik.Windows.Documents.UI.PrintSettings())
 
AddHandler CType(m_oTextBox.ActiveEditorPresenter, Telerik.Windows.Documents.UI.DocumentPrintPresenter).PrintingCompleted, AddressOf MainPage_PrintingCompleted
 
 m_oTextBox.Print("Test Document", Telerik.Windows.Documents.UI.PrintMode.Native)

Catch ex As Exception
                Me.LayoutRoot.Children.Remove(m_oTextBox)
                Throw
End Try
 
Sub MainPage_PrintingCompleted(ByVal sender As Object, ByVal e As EventArgs)
            Me.LayoutRoot.Children.Remove(m_oTextBox)
 End Sub

where TextArea.Document is another RadRichtextBox (use just for the example to populate m_oTextBox )


The problem is that PrintingCompleted doesn't work properly and even if I put a breakpoint in MainPage_PrintingCompleted
it will never be used. Runtime does't go into the function.
0
Alex
Telerik team
answered on 13 Jul 2011, 04:30 PM
Hello Anthony,

It's nice to see that you've reached so far on your own. However there is no need to set the ActiveEditorPresenter property to a new instance of DocumentPrintPresenter. This is done internally inside the Print method of the RadRichTextBox. In fact this is the reason why your event handler isn't called.

If you need to use the printing functionality the RadRichTextBox instance should be involved in the layout passes of the Silverlight application. That's why you should add the control to the visual tree and it should not be collapsed. If the Visibility of the the rich text box is set to Collapsed it is not measured/arranged by the Silverlight layout system. So the recommended approach if you want to use "hidden" RadRichTextBox for printing is to set the Opacity property to 0.

Kind regards,
Alex
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Anthony
Top achievements
Rank 1
answered on 20 Jul 2011, 07:03 AM
Thank you very much for your answer, but if I delete 
m_oTextBox.ActiveEditorPresenter = New Telerik.Windows.Documents.UI.DocumentPrintPresenter(New    Telerik.Windows.Documents.UI.PrintSettings())
  

I have an exception 

Unable to cast object of type 'Telerik.Windows.Documents.UI.DocumentPrintLayoutPresenter' 
to type 'Telerik.Windows.Documents.UI.DocumentPrintPresenter'.

in

AddHandler CType(m_oTextBox.ActiveEditorPresenter, Telerik.Windows.Documents.UI.DocumentPrintPresenter).PrintingCompleted, AddressOf MainPage_PrintingCompleted


Don't understand what 's the problem???
0
Iva Toteva
Telerik team
answered on 25 Jul 2011, 05:04 PM
Hello Anthony,

The event is not fired, because RadRichTextBox creates a new DocumentPrintPresenter when you invoke the print method/command. Therefore, the PrintingCompleted event of the print presenter you create is never fired. We will review the API, so that it would be possible to detect when printing has been completed.

All the best,
Iva
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Anthony
Top achievements
Rank 1
answered on 26 Jul 2011, 01:30 AM
Thank you for the answer.

As I understand that's not possible now to catch the PrintCompleted event until you fix API.That event is really important for me because I try to close a screen where I call the Print function and it throws an exception.It happens because SL still works with printing when I close a window(actually a UserControl).Therefore,I need to close a window in the PrintCompleted event handler but not after calling the Print function......And now I am stuck
0
Iva Toteva
Telerik team
answered on 29 Jul 2011, 08:26 AM
Hello Anthony,

We do agree that this event will be suitable for a broad range of scenarios and will make sure to add it to the API as soon as possible, in the upcoming Q3 at latest.

Kind regards,
Iva
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
RichTextBox
Asked by
Anthony
Top achievements
Rank 1
Answers by
Anthony
Top achievements
Rank 1
Alex
Telerik team
Iva Toteva
Telerik team
Share this question
or