This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
A PictureBox Problem
I have a TabPage which hosts some custom PictureBox controls. What I do here is drawing some IC packages which user can click on theire pins to get some info. User can add multiple of this pictureboxes to the tabpage and move them around in the tabpage.
My problem is that this pictureboxes are transparent, only when they are not over each other. In the image below you see two of this pictureboxes added to tabpage. The tabpage has a blue background, in fact, it doesnt matter what color it has, the pictureboxes will have theire undrawn areas transparent to the tabpage:
But as soon as I move any of thise pictureboxes above another, it will not be transparent anymore:
This is the code that produces raw Image that I will draw on it:
//Setting up image area
Image = new Bitmap(requiredImageWidth, requiredImageHeight, PixelFormat.Format32bppArgb);
Image.MakeTransparent();
The rest are default settings I didnt change anything else. What do you think causing this behaviour?
From this article, this is what's causing this behaviour :
Transparent controls in WinForms are transparent relative to their parent, not to other controls. Transparency in WinForms is more akin to camouflage than true transparency. A transparent control doesn’t actually let you see the control behind it through the form. It asks its parent to draw its own background on the "transparent" control. This is why a transparent control shows the form behind it, but covers up any other controls.
There is an accepted answer to your problem here (A PictureBox Problem)
Related
I'm trying to place a transparent and borderless child (WinForm) form on top of another child (WinForm) form that is opaque, but I'd like to retain the ability to directly click on the transparent form. There are a few answers on the web regarding making a transparent form that can be clicked through, but I want to make one that I can click on.
I've found this answer, which shows that setting my transparent form's BackColor and TransparencyKey to something specific like Color.Red achieves the desired behavior. However based on this answer, it seems this behavior between certain Colors and TransparencyKey may actually be a long-running bug.
Ideally I don't want to rely on a bug to achieve a desired effect. What would be a more "appropriate" approach for making a clickable, transparent, and borderless (WinForm) form?
Update (Additional Context):
I'm basically creating a screen pixel previewer for color data extraction.
Overlay forms containing captured bitmap(s) of the screen area.
Another form that gives a visual indicator for the pixel area being previewed (small black box in the below snapshot). This form is placed above the bitmap forms. I have this form as transparent (to see through to the below bitmaps), but I still want to be able to click on it for event processing.
Without the TransparencyKey = BackColor = Color.Red trick, clicking within the small black box causes focus to move to the below bitmap form, which then covers up the small box form and the preview window showing the zoomed view. The purpose of the click is to capture the cursor position for additional processing. I can work around this by immediately giving focus back to the small box + preview forms, but that occasionally causes flicker.
I have a transparent form in C# and on top of the form I have a splashscreen picturebox with an image. The form's backcolor is actually just Control gray. I also just set the form's transparencykey to Control gray as well. I used the tutorial here to make the form transparent: How to design a cool semi transparent splash screen?
The image is stretched over the picturebox to make it fit nicely on all computer screen resolution. Here is the original image, notice that it has a transparent left side with squares which does not have any borders.
OriginalImageInPhotoshop
However afterwards, the form has these ugly borders on the left side of the image that are the same color as the backcolor & transparencykey (in this case, Control gray). If I place the form over a black background, you can quite visibly see this. How can I get rid of this?
Problem
So far, only remedies I have found is to either not have the image set to stretch in the picturebox (but that would cause it to appear different on every computer screen!) or perhaps theres another way to make a form transparent...
I have an array of picture boxes that are arranged in a square. I want to put a larger, mostly transparent picture box over the top. But when I do it covers the other picture boxes and just draws the background of the form.
Is there a way to get it to have all the other picture boxes show where it is transparent?
Transparency in WinForms isn't great. Some controls have transparency support, others don't. Some controls can be subclassed to enable this (by calling Control.SetStyle() with the SupportsTransparency flag). I believe this can be done with PictureBox.
However, transparency in all WinForms controls works by having the transparent control call its parent control to draw the background before the child control draws. This means that you cannot have two sibling controls and expect transparency on one to show through to the other. Sorry!
All that said, it would be possible to code your own workaround to support this. It would involve subclassing PictureBox and clever coding in the OnPaint override to locate sibling controls and manually trigger painting of them into in-memory bitmaps. Lots of gotchas with this approach.
Try WPF!
Here's a tip to get the desired result:
Create multiple copies of your top image.
Add each copy to the Controls of each picture box it should cover.
Adjust location of each copy according to the offset of each picture box to be covered.
So you will see every copy of your big image covering each picture box as if they were a single image.
The following picture represents a panel over a WebBrowser control in c#.
However, if i put the panels background property to 'transparent', it will show the color 'Silver' as my form's background is silver.
My question is; how can I draw a overlay over my custom WebBrowser control so that when it is 'transparent', it will show the WebBrowser control instead of the form's background color.
Thanks.
I believe it comes down to the OnPaint methods of panels.
Where there are multiple controls overlapping each other only the top control is drawn for that area of the screen. By making the control transparent, you are making that area of the screen the forms background colour
I believe this question has some suggestions on solutions; this question seems to point towards the OnPaintBackground more specifically also
Question link
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Transparent images with C# WinForms
I am coding an app which will have a No Border. It will also have a BackgroundImage[which would be displayed as a slideshow; changed with a timer].
Sample Image [you may need to download this to experience the transparency] :
I have tried the following two methods to accomplish this :
Using WindowsFormsApplication :
I used the TransparencyKey property of the Form along with setting the same Background Colour.[I used Fuchsia]. Now some of the pixels in the border had the colour Fuchsia.
Using WindowsPresentationFoundation :
I used the AllowsTransparency of the Window and set the Background to the Image and the image was displayed correctly with transparency. Now I have to add another image at a point [by setting the margin] which i noted before in Paint.
For Example : I had the image cropped from the original background and then i have place it in the correct place in the form by setting the margin noted before.
But this causes to set a wrong margin!
Update :
In WPF, If I use the BackgroundImage in the Grid, it solves the margin problem but the Transparency just does not work and makes the transparent regions white!
Please give some hints to get out of this problem!
It is a problem caused by the image. You can see it when you load it in, say, Paint.NET and zoom in so you can see the individual pixels. The upper left corner looks like this:
Note how the pixels on the edge are partially transparent. So if you draw this image on top of a background of, say, Fuchsia then those edge pixels are no longer gray, they blend with the background and produce a different color. Which no longer matches the TransparencyKey so the video adapter won't filter them. You'll see them as a fringe of various shades of magenta.
You'll need to edit the image to give it a "hard" edge without any transparency.
In WPF window:
WindowStyle=None
AllowsTransparency=True
Background=Transparent
And then put an image with your content doesn't work?