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 :-)
Cory charlton
source share