2

I have two controls located on Windows Form. Problem is that these two controls have specific form and they intersect.

When I put first control before the second one it looks like this:

enter image description here

When I change order it looks like this:

enter image description here

How can I resolve such things properly?

walruz
  • 1,135
  • 1
  • 13
  • 33
  • 2
    You can change the shape of control by changing its region, like this [RoundCornerControl](http://stackoverflow.com/a/32991419/3110834) or this [Triangular PictureBox](http://stackoverflow.com/a/35467736/3110834). If you don't need to change the shape of control and you only need a transparent renderin, you can take a look at this [Transparent PictureBox and Transparent Label](http://stackoverflow.com/a/36102074/3110834) – Reza Aghaei Apr 25 '16 at 14:46
  • 1
    @Reza Aghaei: Thank you!!! RoundCornerControl did the trick! Cound you please write it like answer (not just comment)? – walruz Apr 25 '16 at 15:22
  • Great! You're welcome :) Instead of posting a duplicate answer, I think it's better to kindly vote for questions and answers which you find helpful and you liked them :) – Reza Aghaei Apr 25 '16 at 15:31

1 Answers1

1

WinForms controls cannot do a true transparency. Their transparency is just to take the BackColor of their parents. If those controls are all custom painted (they look as if they are), you should draw the whole part in one control, if possible.

If not, consider to render the orange background in the control causing the black corner in the second picture as well. So in fact you'll have two different controls rendering parts of the orange area but it will look like it is just one.

If you look at the image, other controls have to render the parts above and left of the red lines. The controls attached to those sides have to draw the gray area and so I assume that there's a quite complex painting algorithm you have to adopt to draw the orange area as well.

Waescher
  • 5,361
  • 3
  • 34
  • 51
  • Unfortunately, I cannot do it, I cannot merge them. – walruz Apr 25 '16 at 14:30
  • Your suggestion does not sound like fun :) I was wondering if I should use Layered Windows or another form with Owner property properly set and transparent inner block. What do you think? – walruz Apr 25 '16 at 14:36
  • I don't know the complexity of the arranged controls but what about rendering the contents to an image and put it into the back of the form? Then, you could place custom-drawn controls onto that image. – Waescher Apr 25 '16 at 14:36
  • having a floating form sticked to the parent seems not to be a good idea to me. You'd have to handle a lot of things like preventing AltF4, keeping moved windows in sync, what about Alt-Tab, ... – Waescher Apr 25 '16 at 14:39
  • Does bringing the black button to the front not make it draw correctly? – BugFinder Apr 25 '16 at 14:41
  • @BugFinder I think that's what the second image shows us. The button is not round, because WinForms does not support custom shaped controls. That's what causes the black corner. – Waescher Apr 25 '16 at 14:44
  • bleh. that is so not what you need :( I would have thought with button on top, and setting colour to lime green or something and using that as the transparent colour that these things would work out. – BugFinder Apr 25 '16 at 14:46
  • the transparent color thing does just work on forms itself. It is called `TransparencyKey`. But that's not for controls placed on forms. – Waescher Apr 25 '16 at 14:47
  • @BugFinder: Orange one is panel with OpenGL rendering to it. Round one is just several gif files which I use to animate the control. – walruz Apr 25 '16 at 14:58