473,387 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Windows forms with Transparent Backgrounds

Well I seem to have an interesting problem. I have an application that
where I am setting the BackgroundImage and the TransparencyKey set in code.
These are both set after the InitializeComponent() in the constructor of the
form. This works great on my computer Windows XP Pro; however on some other
computer the TransparenecyKey isn't working and you see the horrible green
color that shouldn't be there. This doesn't happen on all machines just
some. I even went as far as pulling the TransparenacyColor from a single
pixel from the image at run time so I could make sure I was getting the
exact color.

Any thoughts?

Eric Renken
Apr 24 '07 #1
4 5087
"Eric Renken" <Er********@newsgroup.nospamwrote in message
news:O7**************@TK2MSFTNGP05.phx.gbl...
Well I seem to have an interesting problem. I have an application that
where I am setting the BackgroundImage and the TransparencyKey set in
code. These are both set after the InitializeComponent() in the
constructor of the form. This works great on my computer Windows XP Pro;
however on some other computer the TransparenecyKey isn't working and you
see the horrible green color that shouldn't be there. This doesn't happen
on all machines just some. I even went as far as pulling the
TransparenacyColor from a single pixel from the image at run time so I
could make sure I was getting the exact color.
Probably, the computers where it is failing have the video adapter set to
32-bit color, while those where it is working are set to 24 bits or less. It
is a documented bug of the TransparencyKey (not working at more that 24 bits
of color depth).
Apr 24 '07 #2
My computer (Windows XP) is set to 32-bit and it is working, and it works on
Vista at 32-bit also, but on the other XP machines you are correct it seems
to work below 32-bit mode.

I wonder why it is working correctly on my dev box (Windows XP) at 32-bit.

The work around at
http://support.microsoft.com/default...b;en-us;822495 doesn't work.
When I do this I end up seeing the background color for the form, and you
can't set the Background Color of a form to transparent if you do you get a
nice runtime error.

Eric

"Alberto Poblacion" <ea******************************@poblacion.orgwro te
in message news:ux**************@TK2MSFTNGP06.phx.gbl...
"Eric Renken" <Er********@newsgroup.nospamwrote in message
news:O7**************@TK2MSFTNGP05.phx.gbl...
>Well I seem to have an interesting problem. I have an application that
where I am setting the BackgroundImage and the TransparencyKey set in
code. These are both set after the InitializeComponent() in the
constructor of the form. This works great on my computer Windows XP Pro;
however on some other computer the TransparenecyKey isn't working and you
see the horrible green color that shouldn't be there. This doesn't
happen on all machines just some. I even went as far as pulling the
TransparenacyColor from a single pixel from the image at run time so I
could make sure I was getting the exact color.

Probably, the computers where it is failing have the video adapter set
to 32-bit color, while those where it is working are set to 24 bits or
less. It is a documented bug of the TransparencyKey (not working at more
that 24 bits of color depth).


Apr 24 '07 #3
"Eric Renken" <Er********@newsgroup.nospamwrote in message
news:Oz**************@TK2MSFTNGP05.phx.gbl...
The work around at
http://support.microsoft.com/default...b;en-us;822495 doesn't
work. When I do this I end up seeing the background color for the form,
and you can't set the Background Color of a form to transparent if you do
you get a nice runtime error.
I'm going to say a silly thing, but the above-mentioned workaround takes
the transparencykey color from the pixel at (10,10) in the bitmap. Have you
verified that the color that you are taking is *really* the color that you
chose as transparent?

If you are only doing this to get a non-rectangular form, there's an
alternative aproach that works at all color depths:

1. Override the OnPaint event of the form.
2. In OnPaint, create a new instance of the GraphicsPath class.
3. Use the methods of the GraphicsPath object, such as AddEllipse, to
specify the shape and size required for the form.
4. Set the Region property of the form to a new Region, passing in the
constructor the GraphicsPath object that you have just created.
Apr 24 '07 #4
Alberto,

That isn't a silly question, but yes I change it to work with my stuff, but
I wouldn't put it past me either (darn copy and paste bugs). Well I was
doing more searching and if there would have 1 more lines in that sample it
would have worked. Here is the code I am using now:

System.Drawing.Bitmap Img = new System.Drawing.Bitmap(background);
Color mycolor = Img.GetPixel(transparencyColorLocation.X,
transparencyColorLocation.Y);
Img.MakeTransparent(mycolor);
this.BackgroundImage = Img;
this.BackColor = mycolor;
this.TransparencyKey = mycolor;

What was needed was this.BackColor. Once I added that and it seems to work
now. This is a generic form that is used for splash screens for our
application so the initial background image is passes as a paramater to the
constructor.

Thanks for the help,

Eric
"Alberto Poblacion" <ea******************************@poblacion.orgwro te
in message news:eC**************@TK2MSFTNGP04.phx.gbl...
"Eric Renken" <Er********@newsgroup.nospamwrote in message
news:Oz**************@TK2MSFTNGP05.phx.gbl...
>The work around at
http://support.microsoft.com/default...b;en-us;822495 doesn't
work. When I do this I end up seeing the background color for the form,
and you can't set the Background Color of a form to transparent if you do
you get a nice runtime error.

I'm going to say a silly thing, but the above-mentioned workaround takes
the transparencykey color from the pixel at (10,10) in the bitmap. Have
you verified that the color that you are taking is *really* the color that
you chose as transparent?

If you are only doing this to get a non-rectangular form, there's an
alternative aproach that works at all color depths:

1. Override the OnPaint event of the form.
2. In OnPaint, create a new instance of the GraphicsPath class.
3. Use the methods of the GraphicsPath object, such as AddEllipse, to
specify the shape and size required for the form.
4. Set the Region property of the form to a new Region, passing in the
constructor the GraphicsPath object that you have just created.


Apr 24 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Matthew | last post by:
I am not the most talented programmer to grace the earth by a long shot. But I've got a gripe I need to air about the .NET implementaion of Visual Basic. I can live with alot of the major changes...
3
by: Nick | last post by:
I am working a new application...well actually a series of applications for my company. They want internal users to be able to go to a site and everything regarding security is transparent,...
6
by: MLH | last post by:
I have a logo image that I can paste into MS Paint as an image with clear background. Think of the logo as a black circle in a white, rectangular background. When I paste into Paint, the white...
1
by: Robert W. | last post by:
I've successfully implemented code to change a form's background to a nice blue gradient. It looks great! But I'm having problems adding controls with transparent backgrounds to the form. ...
0
by: Tim Marshall | last post by:
A2003. I rather like the appearance I get with windows themed controls turned on, but I'm running into an odd problem with tab controls. When I set the back style to transparent, it really isn't...
3
by: vikash | last post by:
Hi, I want to develop a windows based application using .Net 2.0 The application will have the heavy UI and it will have the lots of drawing to do on the form. So can any one give me the...
9
by: Bob Alston | last post by:
I am looking for electronic forms software that would integrate well with MS Access. I have a client for whom I built a client database to replace and update one they had that was obsolete and...
4
by: tshad | last post by:
What would be a good way to check programmatically whether a service was running? We have a service that dies periodically and I need to check to see if this service is running. I know how to...
0
by: jobs | last post by:
Hi. I have a menu horizontal on the top. I figured out that if I set this property the black arrow on parent items goes away.. StaticEnableDefaultPopOutImage="False" However, the item is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.