Sunday, April 3, 2011

How to draw on top of winforms controls with transparency?

I have an app with a bunch of controls in it and I want to place a set of cross hairs on top of it. My first attack used a PictureBox and ran into this problem. The solution that fellow proposes, seems a bit... verbose for what I need.

Is there a simple way draw on top of my form? Note that I don't even need the drawing to be part of a control as it doesn't need to do anything but just be there.

From stackoverflow
  • see my question. I was trying to gather all knowledge there:

  • Does a PictureBox with a transparent image have the same problem as a Panel with BackColor set to Transparent? I'm thinking you could have a PictureBox with the crosshair image in it and move that around, instead of drawing it yourself...

    BCS : PictureBox is only transparent re it's parent. As far as other controls go, it paints over them with whatever it's parent would have panted there. There is a picture of that at the top of the link in the question.
  • This eventually worked. I had to play some games though because most of the controls I wanted to draw on were not where it expected them to be.

    Also, it ran into issues when controls were moved; it failed to redraw and stuff moved with the underlying control. This was fixed by forcing invalidation from the move event for anything that might move.

0 comments:

Post a Comment