C # PrintDocument Event Changed

My problem is that I created an advanced RichTextBox control, which uses its own API to add many RichEdit functions that are absent in the standard control (that is, changing one font property to a choice without changing another font property, transferring words to the printer [ for example, WordPad], etc.). As part of the control, I set PrintDocument, which is used to print RichTextBox formatted content. When wordwrap is set to "Wrap To Printer", I send an EM_SETTARGETDEVICE message to the RichTextBox and force it to wrap the appropriate length.

All this works great when something (user / code) changes the WordWrap property of my control. However, if the PrintDocument is changed after this, I do not know how to find out. Therefore, although the user may have changed the fields in PrintDocument, my RichTextBoxEx does not redirect EM_SETTARGETDEVICE for the new width until the WordWrap property is changed.

I see several options for overcoming this, but I'm not a big fan of any of them. Here is what I have:

  • Add the UpdatePrintDocument () method or similar, which will need to be called after something from an external control (that is: pageSetupDialog in the parent form) updated the settings in PrintDocument. Cons: I will distribute control, so I would like to make it as friendly as possible. Although I may remember to call the method anytime I successfully update the PrintDocument parameters, someone else might not. Pro: It's easy to implement.

  • Create a new PrintDocumentEx class that is based on PrintDocument and implements the necessary Modified events. Cons: it may not be enough, you may need to create PrintSettingsEx, PageSettingsEx, etc. Pro: run once, and no one else should worry about it.

I really think that No. 2 is an option that I will have to go with, but it is not very reused for the next instance. I need some similar features. I assume that what I am looking for is a way to bind a โ€œcommon PropertyChanged eventโ€ to any existing class, as this applies in future situations. Trying to see what you have for me :-)

+7
c # printdocument
source share
2 answers

Just after my PrintDocumentEx class (and related) didn't work. Looking into PrintDialog and its associated controls because they use their own methods to actually update PrintDocument. Thus, the events that I bound to the properties in my "Ex" classes never fired because the access element was not activated.

+1
source share

If I understand your question correctly, the information you require is sent when the WordWrap property changes.

When other things are changed, no event updates the print document. The next time you change the WordWrap property, all information is sent.

You can fix this by changing the WordWrap property when you change the property that you want to send to the print document. Change it to a temporary value, then change it again.

+1
source share

All Articles