Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:
http://img341.imageshack.us/img341/5402/policetesttransparency.png
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

to make the Form transparent and not the Controls you do this
You can use 1 form for all of this - easily.
C#
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

C#
FormBorderStyle = FormBorderStyle.None;
 
Share this answer
 
v3
Comments
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 http://img515.imageshack.us/img515/8339/forwebx.png

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.
 
Share this answer
 
v2
Comments
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:
http://img594.imageshack.us/img594/3655/policecardesignlight.png
http://img189.imageshack.us/img189/7750/policecardesigncar.png
alekcarlsen 21-Feb-13 8:17am    
http://imm.io/WVg3 - car with transparency (which works)
http://imm.io/WVgx - lights with transparency (which works)

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900