Click here to Skip to main content
13,202,873 members (57,259 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Refer to my original project to see the background: Creating a NFO Viewer in C# as a beginner[^]

I'm creating a lot of designs for it and lately I wanted to try some applications which are partly semi-transparent. The idea is as the following image shows:
In this case I've created 2 forms, 1 100% visible with all controls and an extra form for the semi-transparant part of the image. So the image I want to use, also has to be split in 2 parts before I import it. After importing and loading on right place, I had to create code that will move both forms at same time. I've done this by adding the 'newlocation' for form2 after moving form1 in with the mousemove method.

Problems I have with this one:
Moving isn't precisely at same time, there's some latency, which causes gaps to appear between the two picture-parts...
When I want to move my application using the 2nd form, it won't work (activates 2nd form focus). As it could override the main form, I had to set alwaysontop, so I can't put any other applications in front of it.
I want to have it working like one form.

I tried to create a partly semi-transparant image using GIMP, export it as png or gif. But it's hard to maintain the transparency and I couldn't import it in Visual Studio (transparency gone).

Is there some way to import partly transparent images in Winforms somehow?
Or is there some way to improve the way when combining 2 forms to make 1 picture?
Any advise would be welcome, this is the first time I try something like this and I almost got it working, but it's not very practical for me.

Thanks beforehand!
Posted 20-Feb-13 22:03pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

to make the Form transparent and not the Controls you do this
You can use 1 form for all of this - easily.
BackColor = Color.Blue;
TransparencyKey = Color.Blue;

use this in your Form_Load
everything that is blue will be transparent.

if you need to remove the border of your form to

FormBorderStyle = FormBorderStyle.None;
DarkTyranno 21-Feb-13 4:44am
If I use 1 form, it will mean that my whole image will be semi-transparent right?
Using TransparencyKey means removing that color, I just want to look through specific parts of the picture as you can see on my demo picture in the question link.
You can see that I already removed the borders as well ;)
alekcarlsen 21-Feb-13 5:00am
nope - what the code does is, it makes the Forms background transparent - then you just need to add an imagebox control - for your "background" -image
check my screenshot

why do you need to use 2 forms?
DarkTyranno 21-Feb-13 5:08am
I don't know if I need to use 2 forms, but for me it was the easiest way to make the lights semi-tranparent.I have form2 with background picture 'lights only' and Opacity xx% and my form1 (mainform) with the flying car and Opacity 100% + all controls. Don't know if there is an easy way that will get the same result yet using Winforms, so if anyone knows, that would be cool.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

DarkTyranno 21-Feb-13 5:18am
Isn't this for complete transparency as well?
I work with Opacity of the form to look through that picture, but this shouldn't work on 1 image in 1 form. The backcolor is already set to white or transparent to remove the big block of that color from around my whole application. If I chose another color from my picture, I'm sure the white returns.
alekcarlsen 21-Feb-13 5:23am
you have a picturebox with the Vehicle - right?
now add another picturebox with the lights in them, overlay and opacity of the picturebox etc.
now add the rest of your controls - turn Form1's Background color blue and set transparencykey to blue - now the background og the form will be transparent.
if this is not what you want, i dont understand your question
alekcarlsen 21-Feb-13 5:26am
link the images if you can
DarkTyranno 21-Feb-13 5:37am
Here are the images I use to try to make the lights SEMI-transparent:
alekcarlsen 21-Feb-13 8:17am - car with transparency (which works) - lights with transparency (which works)
DarkTyranno 21-Feb-13 8:27am
That's also not the case, I already removed the white background myself in PNG format, but I have to set transparency on backgroundcolor (which is transparent).
I just want to use 1 picture, where you can just look through the lights of the car,
or use another option with 2 pictures, but good code to make it run smoothly, as it doesn't in my case.
It's not about the background, it's about the picture itself, I want to look through some parts of it. How can I manage that? (Only solutions I tried was editing outside C# and save picture with partly semi-transparent parts, or make 2 forms and set 1 forms Opacity lower to simulate that. But it gives many extra work of course... :/
DarkTyranno 21-Feb-13 5:32am
I didn't use any pictureboxes for the car nor the lights. Both are Forms without a border set. They contain 2 pictures with a white background which is removed.
This way I could change the opacity of 1 of both forms. If this is possible with pictureboxes too, then I have to check my app again.
Remove the background of form (so no real form/border left), add 2 pictureboxes for both parts, remove borders, change background to picture, remove background from the pictures itself, change opacity for the picturebox with lights.
I don't know if this is possible, but I should try it soon.
alekcarlsen 21-Feb-13 5:38am
Read this to get transparent images

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.171020.1 | Last Updated 21 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100