Make Picture boxes transparent, each overlapping the other with a corner?












2














TL;DR: Look at the picture below



So I'm trying to make a little picture, and I and people around me are kinda out of ideas.



I have a table (the sitting+eating one) in the middle (seen from above), and people sitting around it. Those people are round, as isthe table.



Every person has their own picturebox, I just use one picture, rotate it, and set it as image in the next box.



Thep roblem now is: The PictureBoxes of people on corners overlap the table with empty corner, in the image there is transparency there. It should show the table below it, but instead it shows the background of the Form :(



Edit: All backgrounds are set to transparent, the Form has the marble as background and white ("Window") as background colour.



I put one person in the back and one in the front, so it's easy to see:



Here's what's going on



Edit 2 (same as ocmment):



In the last two days I read this question about 10 times, and not one that described this exact problem has had an actual answer. When trying to push one of those, I was told I should post a new question.



Example: How to make picturebox transparent?










share|improve this question
























  • Downvote reason: This question have been asked and answered repeatedly all over the internet and in specifically stackoverflow. Please refer to the Search and research section in How to Ask.
    – Zohar Peled
    Apr 19 '16 at 7:01












  • In the last two days I read this question about 10 times, and not one that described this exact problem has had an actual answer. When trying to push one of those, I was told I should post a new question.
    – Squirrelkiller
    Apr 19 '16 at 7:03










  • Take a look at this article
    – Zohar Peled
    Apr 19 '16 at 7:07






  • 2




    It is so commonly asked that Microsoft wrote a KB article for it 10 years ago. Best to cut the mouse umbilical cord and write code, use Graphics.DrawImage() instead of controls. Layers of paint.
    – Hans Passant
    Apr 19 '16 at 7:09












  • Trying to read that kb article...as a trainee who just learned c#, I'm gonna sit here in an hour and haven't fully understood that code. Probaby not even conveted to c#, without undestanding it. Trying Zohars solution for now.
    – Squirrelkiller
    Apr 19 '16 at 7:22


















2














TL;DR: Look at the picture below



So I'm trying to make a little picture, and I and people around me are kinda out of ideas.



I have a table (the sitting+eating one) in the middle (seen from above), and people sitting around it. Those people are round, as isthe table.



Every person has their own picturebox, I just use one picture, rotate it, and set it as image in the next box.



Thep roblem now is: The PictureBoxes of people on corners overlap the table with empty corner, in the image there is transparency there. It should show the table below it, but instead it shows the background of the Form :(



Edit: All backgrounds are set to transparent, the Form has the marble as background and white ("Window") as background colour.



I put one person in the back and one in the front, so it's easy to see:



Here's what's going on



Edit 2 (same as ocmment):



In the last two days I read this question about 10 times, and not one that described this exact problem has had an actual answer. When trying to push one of those, I was told I should post a new question.



Example: How to make picturebox transparent?










share|improve this question
























  • Downvote reason: This question have been asked and answered repeatedly all over the internet and in specifically stackoverflow. Please refer to the Search and research section in How to Ask.
    – Zohar Peled
    Apr 19 '16 at 7:01












  • In the last two days I read this question about 10 times, and not one that described this exact problem has had an actual answer. When trying to push one of those, I was told I should post a new question.
    – Squirrelkiller
    Apr 19 '16 at 7:03










  • Take a look at this article
    – Zohar Peled
    Apr 19 '16 at 7:07






  • 2




    It is so commonly asked that Microsoft wrote a KB article for it 10 years ago. Best to cut the mouse umbilical cord and write code, use Graphics.DrawImage() instead of controls. Layers of paint.
    – Hans Passant
    Apr 19 '16 at 7:09












  • Trying to read that kb article...as a trainee who just learned c#, I'm gonna sit here in an hour and haven't fully understood that code. Probaby not even conveted to c#, without undestanding it. Trying Zohars solution for now.
    – Squirrelkiller
    Apr 19 '16 at 7:22
















2












2








2


1





TL;DR: Look at the picture below



So I'm trying to make a little picture, and I and people around me are kinda out of ideas.



I have a table (the sitting+eating one) in the middle (seen from above), and people sitting around it. Those people are round, as isthe table.



Every person has their own picturebox, I just use one picture, rotate it, and set it as image in the next box.



Thep roblem now is: The PictureBoxes of people on corners overlap the table with empty corner, in the image there is transparency there. It should show the table below it, but instead it shows the background of the Form :(



Edit: All backgrounds are set to transparent, the Form has the marble as background and white ("Window") as background colour.



I put one person in the back and one in the front, so it's easy to see:



Here's what's going on



Edit 2 (same as ocmment):



In the last two days I read this question about 10 times, and not one that described this exact problem has had an actual answer. When trying to push one of those, I was told I should post a new question.



Example: How to make picturebox transparent?










share|improve this question















TL;DR: Look at the picture below



So I'm trying to make a little picture, and I and people around me are kinda out of ideas.



I have a table (the sitting+eating one) in the middle (seen from above), and people sitting around it. Those people are round, as isthe table.



Every person has their own picturebox, I just use one picture, rotate it, and set it as image in the next box.



Thep roblem now is: The PictureBoxes of people on corners overlap the table with empty corner, in the image there is transparency there. It should show the table below it, but instead it shows the background of the Form :(



Edit: All backgrounds are set to transparent, the Form has the marble as background and white ("Window") as background colour.



I put one person in the back and one in the front, so it's easy to see:



Here's what's going on



Edit 2 (same as ocmment):



In the last two days I read this question about 10 times, and not one that described this exact problem has had an actual answer. When trying to push one of those, I was told I should post a new question.



Example: How to make picturebox transparent?







c# winforms transparency picturebox






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 23 '17 at 12:24









Community

11




11










asked Apr 19 '16 at 6:56









Squirrelkiller

625818




625818












  • Downvote reason: This question have been asked and answered repeatedly all over the internet and in specifically stackoverflow. Please refer to the Search and research section in How to Ask.
    – Zohar Peled
    Apr 19 '16 at 7:01












  • In the last two days I read this question about 10 times, and not one that described this exact problem has had an actual answer. When trying to push one of those, I was told I should post a new question.
    – Squirrelkiller
    Apr 19 '16 at 7:03










  • Take a look at this article
    – Zohar Peled
    Apr 19 '16 at 7:07






  • 2




    It is so commonly asked that Microsoft wrote a KB article for it 10 years ago. Best to cut the mouse umbilical cord and write code, use Graphics.DrawImage() instead of controls. Layers of paint.
    – Hans Passant
    Apr 19 '16 at 7:09












  • Trying to read that kb article...as a trainee who just learned c#, I'm gonna sit here in an hour and haven't fully understood that code. Probaby not even conveted to c#, without undestanding it. Trying Zohars solution for now.
    – Squirrelkiller
    Apr 19 '16 at 7:22




















  • Downvote reason: This question have been asked and answered repeatedly all over the internet and in specifically stackoverflow. Please refer to the Search and research section in How to Ask.
    – Zohar Peled
    Apr 19 '16 at 7:01












  • In the last two days I read this question about 10 times, and not one that described this exact problem has had an actual answer. When trying to push one of those, I was told I should post a new question.
    – Squirrelkiller
    Apr 19 '16 at 7:03










  • Take a look at this article
    – Zohar Peled
    Apr 19 '16 at 7:07






  • 2




    It is so commonly asked that Microsoft wrote a KB article for it 10 years ago. Best to cut the mouse umbilical cord and write code, use Graphics.DrawImage() instead of controls. Layers of paint.
    – Hans Passant
    Apr 19 '16 at 7:09












  • Trying to read that kb article...as a trainee who just learned c#, I'm gonna sit here in an hour and haven't fully understood that code. Probaby not even conveted to c#, without undestanding it. Trying Zohars solution for now.
    – Squirrelkiller
    Apr 19 '16 at 7:22


















Downvote reason: This question have been asked and answered repeatedly all over the internet and in specifically stackoverflow. Please refer to the Search and research section in How to Ask.
– Zohar Peled
Apr 19 '16 at 7:01






Downvote reason: This question have been asked and answered repeatedly all over the internet and in specifically stackoverflow. Please refer to the Search and research section in How to Ask.
– Zohar Peled
Apr 19 '16 at 7:01














In the last two days I read this question about 10 times, and not one that described this exact problem has had an actual answer. When trying to push one of those, I was told I should post a new question.
– Squirrelkiller
Apr 19 '16 at 7:03




In the last two days I read this question about 10 times, and not one that described this exact problem has had an actual answer. When trying to push one of those, I was told I should post a new question.
– Squirrelkiller
Apr 19 '16 at 7:03












Take a look at this article
– Zohar Peled
Apr 19 '16 at 7:07




Take a look at this article
– Zohar Peled
Apr 19 '16 at 7:07




2




2




It is so commonly asked that Microsoft wrote a KB article for it 10 years ago. Best to cut the mouse umbilical cord and write code, use Graphics.DrawImage() instead of controls. Layers of paint.
– Hans Passant
Apr 19 '16 at 7:09






It is so commonly asked that Microsoft wrote a KB article for it 10 years ago. Best to cut the mouse umbilical cord and write code, use Graphics.DrawImage() instead of controls. Layers of paint.
– Hans Passant
Apr 19 '16 at 7:09














Trying to read that kb article...as a trainee who just learned c#, I'm gonna sit here in an hour and haven't fully understood that code. Probaby not even conveted to c#, without undestanding it. Trying Zohars solution for now.
– Squirrelkiller
Apr 19 '16 at 7:22






Trying to read that kb article...as a trainee who just learned c#, I'm gonna sit here in an hour and haven't fully understood that code. Probaby not even conveted to c#, without undestanding it. Trying Zohars solution for now.
– Squirrelkiller
Apr 19 '16 at 7:22














1 Answer
1






active

oldest

votes


















4














Transparency in winforms is kind of misleading, since it's not really transparency.

Winforms controls mimic transparency by painting the part of their parent control they would hide instead of their own background.

However, they will not paint the other controls that might be partially covered by them.

This is the reason your top most picture boxes hides your big picture box.



You can overcome this by creating a custom control that inherits from PictureBox and override its OnPaintBackground method (taken, with slight adjustments, from this code project article):



protected override void OnPaintBackground(PaintEventArgs e)
{
base.OnPaintBackground(e);
Graphics g = e.Graphics;

if (this.Parent != null)
{
var index = Parent.Controls.GetChildIndex(this);
for (var i = Parent.Controls.Count - 1; i > index; i--)
{
var c = Parent.Controls[i];
if (c.Bounds.IntersectsWith(Bounds) && c.Visible)
{
using (var bmp = new Bitmap(c.Width, c.Height, g))
{
c.DrawToBitmap(bmp, c.ClientRectangle);
g.TranslateTransform(c.Left - Left, c.Top - Top);
g.DrawImageUnscaled(bmp, Point.Empty);
g.TranslateTransform(Left - c.Left, Top - c.Top);
}
}
}
}
}


Microsoft have published a Knowledge base article to solve this problem a long time ago, however it's a bit out-dated and it's code sample is in VB.Net.



Another option is to paint the images yourself, without picture boxes to hold them, by using Graphics.DrawImage method.

The best place to do it is probably in the OnPaint method of the form.






share|improve this answer























  • Woah thanks dude. Not only the best working, but also on of the easiest answers. Had that article too before, just used the whole TranspControl class. Didn't work as well as your solution :).
    – Squirrelkiller
    Apr 19 '16 at 8:14










  • Glad to help :-).
    – Zohar Peled
    Apr 19 '16 at 9:34










  • Here is an implementation of TransparentLabel and TransparentPictureBox which you may find helpful.
    – Reza Aghaei
    Apr 19 '16 at 14:08











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f36710701%2fmake-picture-boxes-transparent-each-overlapping-the-other-with-a-corner%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









4














Transparency in winforms is kind of misleading, since it's not really transparency.

Winforms controls mimic transparency by painting the part of their parent control they would hide instead of their own background.

However, they will not paint the other controls that might be partially covered by them.

This is the reason your top most picture boxes hides your big picture box.



You can overcome this by creating a custom control that inherits from PictureBox and override its OnPaintBackground method (taken, with slight adjustments, from this code project article):



protected override void OnPaintBackground(PaintEventArgs e)
{
base.OnPaintBackground(e);
Graphics g = e.Graphics;

if (this.Parent != null)
{
var index = Parent.Controls.GetChildIndex(this);
for (var i = Parent.Controls.Count - 1; i > index; i--)
{
var c = Parent.Controls[i];
if (c.Bounds.IntersectsWith(Bounds) && c.Visible)
{
using (var bmp = new Bitmap(c.Width, c.Height, g))
{
c.DrawToBitmap(bmp, c.ClientRectangle);
g.TranslateTransform(c.Left - Left, c.Top - Top);
g.DrawImageUnscaled(bmp, Point.Empty);
g.TranslateTransform(Left - c.Left, Top - c.Top);
}
}
}
}
}


Microsoft have published a Knowledge base article to solve this problem a long time ago, however it's a bit out-dated and it's code sample is in VB.Net.



Another option is to paint the images yourself, without picture boxes to hold them, by using Graphics.DrawImage method.

The best place to do it is probably in the OnPaint method of the form.






share|improve this answer























  • Woah thanks dude. Not only the best working, but also on of the easiest answers. Had that article too before, just used the whole TranspControl class. Didn't work as well as your solution :).
    – Squirrelkiller
    Apr 19 '16 at 8:14










  • Glad to help :-).
    – Zohar Peled
    Apr 19 '16 at 9:34










  • Here is an implementation of TransparentLabel and TransparentPictureBox which you may find helpful.
    – Reza Aghaei
    Apr 19 '16 at 14:08
















4














Transparency in winforms is kind of misleading, since it's not really transparency.

Winforms controls mimic transparency by painting the part of their parent control they would hide instead of their own background.

However, they will not paint the other controls that might be partially covered by them.

This is the reason your top most picture boxes hides your big picture box.



You can overcome this by creating a custom control that inherits from PictureBox and override its OnPaintBackground method (taken, with slight adjustments, from this code project article):



protected override void OnPaintBackground(PaintEventArgs e)
{
base.OnPaintBackground(e);
Graphics g = e.Graphics;

if (this.Parent != null)
{
var index = Parent.Controls.GetChildIndex(this);
for (var i = Parent.Controls.Count - 1; i > index; i--)
{
var c = Parent.Controls[i];
if (c.Bounds.IntersectsWith(Bounds) && c.Visible)
{
using (var bmp = new Bitmap(c.Width, c.Height, g))
{
c.DrawToBitmap(bmp, c.ClientRectangle);
g.TranslateTransform(c.Left - Left, c.Top - Top);
g.DrawImageUnscaled(bmp, Point.Empty);
g.TranslateTransform(Left - c.Left, Top - c.Top);
}
}
}
}
}


Microsoft have published a Knowledge base article to solve this problem a long time ago, however it's a bit out-dated and it's code sample is in VB.Net.



Another option is to paint the images yourself, without picture boxes to hold them, by using Graphics.DrawImage method.

The best place to do it is probably in the OnPaint method of the form.






share|improve this answer























  • Woah thanks dude. Not only the best working, but also on of the easiest answers. Had that article too before, just used the whole TranspControl class. Didn't work as well as your solution :).
    – Squirrelkiller
    Apr 19 '16 at 8:14










  • Glad to help :-).
    – Zohar Peled
    Apr 19 '16 at 9:34










  • Here is an implementation of TransparentLabel and TransparentPictureBox which you may find helpful.
    – Reza Aghaei
    Apr 19 '16 at 14:08














4












4








4






Transparency in winforms is kind of misleading, since it's not really transparency.

Winforms controls mimic transparency by painting the part of their parent control they would hide instead of their own background.

However, they will not paint the other controls that might be partially covered by them.

This is the reason your top most picture boxes hides your big picture box.



You can overcome this by creating a custom control that inherits from PictureBox and override its OnPaintBackground method (taken, with slight adjustments, from this code project article):



protected override void OnPaintBackground(PaintEventArgs e)
{
base.OnPaintBackground(e);
Graphics g = e.Graphics;

if (this.Parent != null)
{
var index = Parent.Controls.GetChildIndex(this);
for (var i = Parent.Controls.Count - 1; i > index; i--)
{
var c = Parent.Controls[i];
if (c.Bounds.IntersectsWith(Bounds) && c.Visible)
{
using (var bmp = new Bitmap(c.Width, c.Height, g))
{
c.DrawToBitmap(bmp, c.ClientRectangle);
g.TranslateTransform(c.Left - Left, c.Top - Top);
g.DrawImageUnscaled(bmp, Point.Empty);
g.TranslateTransform(Left - c.Left, Top - c.Top);
}
}
}
}
}


Microsoft have published a Knowledge base article to solve this problem a long time ago, however it's a bit out-dated and it's code sample is in VB.Net.



Another option is to paint the images yourself, without picture boxes to hold them, by using Graphics.DrawImage method.

The best place to do it is probably in the OnPaint method of the form.






share|improve this answer














Transparency in winforms is kind of misleading, since it's not really transparency.

Winforms controls mimic transparency by painting the part of their parent control they would hide instead of their own background.

However, they will not paint the other controls that might be partially covered by them.

This is the reason your top most picture boxes hides your big picture box.



You can overcome this by creating a custom control that inherits from PictureBox and override its OnPaintBackground method (taken, with slight adjustments, from this code project article):



protected override void OnPaintBackground(PaintEventArgs e)
{
base.OnPaintBackground(e);
Graphics g = e.Graphics;

if (this.Parent != null)
{
var index = Parent.Controls.GetChildIndex(this);
for (var i = Parent.Controls.Count - 1; i > index; i--)
{
var c = Parent.Controls[i];
if (c.Bounds.IntersectsWith(Bounds) && c.Visible)
{
using (var bmp = new Bitmap(c.Width, c.Height, g))
{
c.DrawToBitmap(bmp, c.ClientRectangle);
g.TranslateTransform(c.Left - Left, c.Top - Top);
g.DrawImageUnscaled(bmp, Point.Empty);
g.TranslateTransform(Left - c.Left, Top - c.Top);
}
}
}
}
}


Microsoft have published a Knowledge base article to solve this problem a long time ago, however it's a bit out-dated and it's code sample is in VB.Net.



Another option is to paint the images yourself, without picture boxes to hold them, by using Graphics.DrawImage method.

The best place to do it is probably in the OnPaint method of the form.







share|improve this answer














share|improve this answer



share|improve this answer








edited Apr 19 '16 at 9:40

























answered Apr 19 '16 at 7:32









Zohar Peled

52.4k73273




52.4k73273












  • Woah thanks dude. Not only the best working, but also on of the easiest answers. Had that article too before, just used the whole TranspControl class. Didn't work as well as your solution :).
    – Squirrelkiller
    Apr 19 '16 at 8:14










  • Glad to help :-).
    – Zohar Peled
    Apr 19 '16 at 9:34










  • Here is an implementation of TransparentLabel and TransparentPictureBox which you may find helpful.
    – Reza Aghaei
    Apr 19 '16 at 14:08


















  • Woah thanks dude. Not only the best working, but also on of the easiest answers. Had that article too before, just used the whole TranspControl class. Didn't work as well as your solution :).
    – Squirrelkiller
    Apr 19 '16 at 8:14










  • Glad to help :-).
    – Zohar Peled
    Apr 19 '16 at 9:34










  • Here is an implementation of TransparentLabel and TransparentPictureBox which you may find helpful.
    – Reza Aghaei
    Apr 19 '16 at 14:08
















Woah thanks dude. Not only the best working, but also on of the easiest answers. Had that article too before, just used the whole TranspControl class. Didn't work as well as your solution :).
– Squirrelkiller
Apr 19 '16 at 8:14




Woah thanks dude. Not only the best working, but also on of the easiest answers. Had that article too before, just used the whole TranspControl class. Didn't work as well as your solution :).
– Squirrelkiller
Apr 19 '16 at 8:14












Glad to help :-).
– Zohar Peled
Apr 19 '16 at 9:34




Glad to help :-).
– Zohar Peled
Apr 19 '16 at 9:34












Here is an implementation of TransparentLabel and TransparentPictureBox which you may find helpful.
– Reza Aghaei
Apr 19 '16 at 14:08




Here is an implementation of TransparentLabel and TransparentPictureBox which you may find helpful.
– Reza Aghaei
Apr 19 '16 at 14:08


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f36710701%2fmake-picture-boxes-transparent-each-overlapping-the-other-with-a-corner%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python