views:

2027

answers:

2
+1  Q: 

XOR Drawing in C#

I am a trying to learn C# .Net.

I had written small (hobby) Analog Clock application in VB sometime ago(edit: VB6, to be precise), and I thought I will rewrite in C#.NET, as part of my learning process.

In the VB application, I drew the hands of the clock in XOR Drawmode, so that I have to move the second hand, I just had to redraw it in the previous position and then draw the current position - I need not refresh the whole Form. All I did was

Me.DrawMode = vbNotXorPen

and then

Me.Line...

on a VB Form

In C# I don't find an equivalent Xor Pen Draw mode.

I found

ControlPaint.DrawReversibleLine

somewhere on the net, but I am not sure whether ControlPaint is meant for such purposes (and I don't understand based on what co-ordinate system ControlPaint is drawing)

Is there an equivalent to XOR drawing in C#.NET? Or is there a better way to do what I am doing (with the best performance)

(Both VB and C# are my hobbies. So feel free to correct me wherever I am wrong)

+2  A: 

IMHO, until and unless you are targeting some really slow computers, you don't need to optimize performance by using XOR technique.

Since you'd be drawing the second hand only once in a second, a complete redraw of the clock would be much better. Also, the second hand will "look" good if drawn directly, and use smoothing mode set to Anti alias for a more cleaner look.

To optimize performance, you can create a bmp for clock every one minute and then draw the second hand upon it.

nullDev
+2  A: 

.NET/GDI+ does not support XOR drawing. You'll have to workaround it by using p/invoke calls of several native functions.

See the link below for more information

http://www.vbaccelerator.com/home/net/code/libraries/Graphics/ZoomIn/article.asp

arul