473,748 Members | 2,574 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 InitializeCompo nent() in the constructor of the
form. This works great on my computer Windows XP Pro; however on some other
computer the TransparenecyKe y 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 TransparenacyCo lor 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 5107
"Eric Renken" <Er********@new sgroup.nospamwr ote in message
news:O7******** ******@TK2MSFTN GP05.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 InitializeCompo nent() in the
constructor of the form. This works great on my computer Windows XP Pro;
however on some other computer the TransparenecyKe y 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
TransparenacyCo lor 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.o rgwrote
in message news:ux******** ******@TK2MSFTN GP06.phx.gbl...
"Eric Renken" <Er********@new sgroup.nospamwr ote in message
news:O7******** ******@TK2MSFTN GP05.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 InitializeCompo nent() in the
constructor of the form. This works great on my computer Windows XP Pro;
however on some other computer the TransparenecyKe y 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
TransparenacyC olor 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********@new sgroup.nospamwr ote in message
news:Oz******** ******@TK2MSFTN GP05.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(backgrou nd);
Color mycolor = Img.GetPixel(tr ansparencyColor Location.X,
transparencyCol orLocation.Y);
Img.MakeTranspa rent(mycolor);
this.Background Image = Img;
this.BackColor = mycolor;
this.Transparen cyKey = 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.o rgwrote
in message news:eC******** ******@TK2MSFTN GP04.phx.gbl...
"Eric Renken" <Er********@new sgroup.nospamwr ote in message
news:Oz******** ******@TK2MSFTN GP05.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
5105
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 to the structure and syntax of the code but I thought the purpose of re-engineering the damn thing would result in improved performance all around, well the .NET seems to really suck doing things graphically on forms that VB6 Seemed to do fine....
3
2720
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, however we will have brokers and customers that also need to connect and will require a username and password. In this case we were going to store their credentials in a SQL database. Internal users will have the ability to access the same resources...
6
2361
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 back- ground can be made "clear" so it does NOT overwrite other image data when I'm pasting into an existing picture. Just the circle would appear after the paste is made. However, when I try to accomplish the same thing with an Access 97 form,...
1
2254
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. Specifically I'd like to add an image and a label with a transparent background. At design time everything appears okay but when I run the code it no longer works. Might there be some articles on how to do this?
0
1769
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 transparent. I'm finding instead of one text box or a button that I'd like to have on the form "shining through" and displaying with all pages, it's as if the tab control keeps the odd colour background it generates. I originally developed the...
3
7648
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 direction how can i handle the different issues that will arise in the same due to paint event and due to other issues.
9
2101
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 not doing what they want. They are wanting to move on to the next step and automate most of their forms. some are boilerplate forms that are simple printed without change. some are boilerplate but require signatures from client and rep. Others...
4
4180
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 check to see if the status is in stopped or running mode. But that doesn't tell me if it is actually running. I need to know this so that if it happens I can programmatically start the same service on another machine.
0
2102
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 still wider than other items accross than items
0
8996
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8832
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9562
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9386
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
6078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3319
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2217
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.