How to make any control shape irregular in c# - c#

how to make any control of win application transparent. i want that i will assign a background image for the target control and will invoke a routine and that routine will create that control transparent in such a way that only image will visible. as a example suppose image has assign to picture box. the picture shape is not square rather irregular. if i can make picture box transparent then user will see the image only. basically i want to make a picture box or any control irregular shape. how to achieve it through code in c#.
thanks

In WPF, transparency is quasi for free. For the image-element, assign a png-image with an alpha mask and the image will be rendered with active transparency.
For controls with an solid background, you generally have to set the Background to a transparent Brush:
If you want to make a whole window partial transparent, you have to remove the border, set the window style to none, set the background brush to a transparent brush, and set the AllowsTransparency-property of the window to true.

there is one for ordinary winform at
http://www.youtube.com/watch?v=K_JzL4kzCoE

Related

c# set PictureBox.BackroundColor to transparent even if there are more than one control below

I am trying to set the BackgroundColor of a PictureBox transparent. I know that this just copies the Foreground from the Control below to the Background to the Control on top. This works fine until I have more than just 1 control below.
Imagine I had a 4x4 PictureBox pBOverlay. On top of this overlay I want to put one single PictureBox pBonTop which has the height and width from the 4x4 Overlay. How can I set the Background to transparency? Is this even possible?

Make a PictureBox transparent and allow it to be moved

I would need a picturebox that contains a graphic for an actor. The actor is placed on PictureBoxes that contain a tileset graphic. The actor should be able to move freely which i already did, but the transparent .PNG Actor-Image has a control-colored background when I load it into the form.
Question:
How could I make the background of this Image transparent AND allow to be moved?
The problem with windowsforms is that its control does not have true transparency
The transparency of a control is based on the BackgroundColor or BackgroundImage of its parent and that is why your PictureBox is Control-Colored
Now if you want to make it true transparency you have some options
Draw everything yourself
You can use the power of gdi+ or Graphics to draw everything, but only the needed ones
Handle the draw of the control
This could be a tricky one, you can override the method OnPaint and OnPaintBackground of the picture box so it do not redraw its background (Control-Colored), the bad side of this is that it will have a lot of flickering and buggy background on movement
Use another techology
I'm not sure but if I'm not mistaken you could use wpf for this, altough it could change your entire project

Can I create a transparent background on a PictureBox in WinForms?

I want to make the background of a PictureBox control transparent. In the PictureBox (rectangular shape), I placed an icon (circular in shape). I want to make the icon transparent so that the other portion underneath the icon is visible.
I have tried setting the PictureBox.BackColor property to "Transparent", but it doesn't work. I also tried to set it during runtime with the Color.FromArgb method, but it doesn't work either.
Is there any solution to this problem?
Setting pictureBox.BackColor = Color.Transparent; definitely should work.
Also verify if you are setting alpha channel of color when using Color.FromArgb(0, 0, 0, 0); (this is a first parameter, zero means transparent color)
And, of course, make sure your icons have transparent background.
If using WinForms then Setting the background color to transparent won't work as transparency handling is not a cascading system - you can only (in most cases) set transparency (or rather the opacity) of a control overall using the Opacity property, however this will alter the alpha channel of the entire control display giving your images a see-througness.
One solution might be to set the background color of the PictureBox to be that of the control beneath it (the color of the form, for example). But this may not suffice in your situation.
hi you must set the icon on the other portion underneath the icon by using this
icon_pictureBox_name.Controls.Add(other_portion_picturBox_name);
and after that you can set the PictureBox.BackColor property to "Transparent" and it will work ;)

How do I scrape what a transparent panel shows into a bitmap?

Question:
How do I scrape what a transparent panel shows into a bitmap?
Background:
I need to make a form that sits on top of everything and blurs part of the screen but doesn't stop the user from interacting with it. Odd... I know.
I created a form and added a panel to it. I then set the set background color of the panel to red. Then set the form's TransparentKey property to red and topmost = True.
So now I have a transparent panel. Cool. I can interact with the app below it. Cool. Now I just need to add the blur. I would like to take what is showing on panel1 and blur it then display on panel2 that sits over the top of panel1. Or at least that is the idea.
Important detail:
DrawToBitmap() just shows the red background.
This is running on XP.
Yes, DrawToBitmap(). But not on the transparent panel, on the one that's underneath it. If that 'panel' isn't actually yours then you have to use Graphics.CopyFromScreen().
Not sure what you intend to do with it, but drawing the blurred image in the transparent panel will make it non-transparent and you cannot interact with the underlying window anymore. Also, don't use Red, you'll get unintended transparency if the underlying window contains any red. Color.Fuchsia is a good choice, it is a fuchsed-up color.

Setting my PictureBox to transparent background color doesn't really make it transparent. Bug?

Here's what I have in VERY simple easy to grasp terms.
My form background is Blue.
I created a gradient image from white to the Blue from the form background. This is to give the form a nice gradient look. I added a picturebox to my Form and set this image as the Image.
I added a picturebox with a Logo on top of the gradient Picturebox, but it's 'grabbing' the Form background color and not respecting the transparent background image I wanted it to grab.
So:
Blue Form -> Huge pictureBox with gradient -> Small picturebox thats supposed to respect the gradient.
Help please!
I think this might be as the PictureBox is not a control container. So this implies that when you drag the button picture box onto the main picture box, it is not actually a child of the picturebox, but rather of the form.
You would notice that if you were to do he same with a panel (set the form blue, panel background image, and place the button picture box control on the panel) it would show transparent to the panel control.
Why not rather set the Form BackgroundImage, avoid the Huge Picture Box, and set the small picture box on the form itself.

Categories