|
Prevent Flickering in a RichEditIf you're doing a series of operations with a RichEdit and you only want the user to be able to see the end results and not everything done to the RichEdit to get there, you need to stop the RichEdit from redrawing. You can use the Perform function with EM_SETREDRAW, but a problem occurs if a function that turns redraw off and then on calls another function that turns redraw off then on. The called function will turn redraw back on before the callee would have, and the callee probably doesn't want it turned back on until it turns it back on itself.
Here's the solution. You create a property called RedrawOn which you assign a boolean to turn
on or off. The thing is, you have to assign it true as many times as you assign it false for
redraw to be turned back on. For instance, if you assign RedrawOn to false 5 times, you must
assign RedrawOn to true 5 times before it comes back on. Below is the code to implement this.
I assume the programmer has a RichEdit called Edit on a Form called MainForm.
If you want redraw on the have a read property, just make redrawCount a data member of MainForm and write a function that returns true when redrawCount = 0. |