Form With customized Borders and Transparent Background [duplicate] - c#

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?

Related

Black in my picturebox c#

when I use an image to a URL in my picture box I have black in here
Image = http://prntscr.com/cx1nre
I am known it's because my panel is on Highlight but when I use " Transparent " it give me a black in my picture box... example = http://prntscr.com/cwu9ev
Anyone can help me please?
After understanding your question (one picture over other and the top with transparency), your problem is how .net transparency works, it's not real transparency, it copies the background of the container.
So, to make it work instead of two picture boxes add a panel and a picturebox inside the panel, set the backgroundimage of the panel to the image you wanted to use, and then set the overlay image on the picturebox. As .net copies the container's backgrond, as you added the picture box as a child of the panel the picture box will copy the image and the transparency would work as you expected.
Only caveat is that you need to load manually the image, but there are plenty of examples on how to load it.
Also, there's even a better approach: instead of two pictureboxes just add one, load into a Bitmap the background you want, retrieve a Graphics object from it, draw the second image with Graphics.DrawImage and then use the bitmap as the Image for the picturebox. It's more complicated but it's the most efficient way to do this.

Scale Bar in C# WPF with EMGU

Is it possible to overlay a scale bar into an image been displayed in WPF using EMGU like in the following picture?
Or like in Bing Maps.
I have images that are 1024x600 size, and I want to display on the image the scale of scale bar (I know the pixel size).
For example in the above image I would like to overlay to my image a green line and say that this line is 5cm.
I know how to do the calculations that relate the length of the line to the actual dimensions, however I don't know how to create that scale bar and overlay it on top of the image.
Any information about what approach I shall follow would be welcome!
Thank you.
In WPF I have found the easiest way to do this is to use your image as the background of a Canvas control. Canvas controls allow the placement of any control anywhere on the canvas. I am using a similar technique in a product we are developing.
Doug

Transparency over multiple pictureBoxes

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.

PictureBox with transparent background [duplicate]

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)

How to make any control shape irregular in 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

Categories