views:

64

answers:

2

Hi, I'd like to draw a progress bar with percentage in its center, but I'd like the text to have negative (contrasted) color of the background.

So the part of the text that is over the filled portion of ProgressBar would be white and the part over unfilled portion would be white.

I could do this simply by "cheating"

  • painting the black part of the text first
  • painting the progress rectangle (it would cover the part to be hidden)
  • painting the white text over the progress rectangle only (clipping it)

The performance impact of painting the text twice is negligible in this application, but I'm interested if there is some simple way to do it in two steps only (like having the progress bar somehow invert the already painted text) with blending.

A: 

You can use XOR to calculate the negative (inverted) color;

Public Function InvertColor(color As Long) As Long
    Return (color Xor &HFFFFFF)
End Function
Rhapsody
That is no problem, I know the base and inverted color, but I'm asking about how to do "XOR" blending in graphics
Axarydax
+2  A: 

What you're doing is fine. Old tricks like SetROP2() don't work anymore with text getting anti-aliased, especially with ClearType rendering. Getting the aliasing pixels with the wrong color is very noticeable. Graphics.CompositingMode accordingly doesn't support the effects anymore.

Hans Passant