473,387 Members | 1,863 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.

Transparent Bitmap Drawn onto Transparent control

Hi there,

I have a usercontrol that inherits from Windows.Forms.Button.

In the OnCreateControl method I set the style of the control so that it supports transparent backcolor and set the background color to transparent.

.....

Protected Overrides Sub OnCreateControl()

MyBase.OnCreateControl()

Call SetStyle(ControlStyles.SupportsTransparentBackColo r, True)

BackColor = Color.Transparent

End Sub

.....

I have an image with magenta sections which I remove using Bitmap.MakeTransparent(Color.Magenta). Unfortunately when I draw this image onto the form the parts that were previously magenta, get drawn as black.

My question is, how do I draw this image with the magenta parts as transparent?

Many thanks in advance.

Nick.

Jul 10 '07 #1
3 4851
Hi again,

I've changed the transparent initialisation and moved it to the
CreateParams override,

Protected Overrides ReadOnly Property CreateParams() As
System.Windows.Forms.CreateParams
Get
Dim pCPsParams As CreateParams = MyBase.CreateParams()
pCPsParams.ExStyle = pCPsParams.ExStyle Or &H20
Return (pCPsParams)
End Get
End Property

I am also overriding OnPaintBackground so that no background is drawn.
Unfortunately I still get black bits...

Nick.

"NickP" <a@a.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
Hi there,

I have a usercontrol that inherits from Windows.Forms.Button.

In the OnCreateControl method I set the style of the control so that it
supports transparent backcolor and set the background color to transparent.

.....

Protected Overrides Sub OnCreateControl()
MyBase.OnCreateControl()
Call SetStyle(ControlStyles.SupportsTransparentBackColo r, True)
BackColor = Color.Transparent
End Sub
.....

I have an image with magenta sections which I remove using
Bitmap.MakeTransparent(Color.Magenta). Unfortunately when I draw this image
onto the form the parts that were previously magenta, get drawn as black.
My question is, how do I draw this image with the magenta parts as
transparent?
Many thanks in advance.
Nick.
Jul 11 '07 #2
I have changed my image to a PNG with the transparent parts in already.
Unfortunately I am getting the same issues,

My drawing routine contains the following code,

Call pevent.Graphics.Clear(Color.FromArgb(255, 0, 0, 0))

Call pevent.Graphics.DrawImage(buttonMap, _
New Rectangle(0, 0, Width, Height), _
getCurrentFrameSourceRect(), _
GraphicsUnit.Pixel)

It seems that there is no way to clear the surface before redrawing as it
just comes out as black. How do I completely remove all colour information
from the back before redrawing? Ideally |I want to do this all to a back
buffer then redraw that, but at current I can't get it working either way.

Thanks for any help in advance.

Nick.
"NickP" <a@a.comwrote in message
news:ef**************@TK2MSFTNGP02.phx.gbl...
Hi again,

I've changed the transparent initialisation and moved it to the
CreateParams override,

Protected Overrides ReadOnly Property CreateParams() As
System.Windows.Forms.CreateParams
Get
Dim pCPsParams As CreateParams = MyBase.CreateParams()
pCPsParams.ExStyle = pCPsParams.ExStyle Or &H20
Return (pCPsParams)
End Get
End Property

I am also overriding OnPaintBackground so that no background is drawn.
Unfortunately I still get black bits...

Nick.

"NickP" <a@a.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
Hi there,

I have a usercontrol that inherits from Windows.Forms.Button.

In the OnCreateControl method I set the style of the control so that it
supports transparent backcolor and set the background color to
transparent.

....

Protected Overrides Sub OnCreateControl()
MyBase.OnCreateControl()
Call SetStyle(ControlStyles.SupportsTransparentBackColo r, True)
BackColor = Color.Transparent
End Sub
....

I have an image with magenta sections which I remove using
Bitmap.MakeTransparent(Color.Magenta). Unfortunately when I draw this
image onto the form the parts that were previously magenta, get drawn as
black.
My question is, how do I draw this image with the magenta parts as
transparent?
Many thanks in advance.
Nick.

Jul 11 '07 #3
Hi again,

Okay I finally have it drawing correctly, but by inheriting from Panel
rather than Button, so it's not ideal tbh...

Nick.

"NickP" <a@a.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>I have changed my image to a PNG with the transparent parts in already.
Unfortunately I am getting the same issues,

My drawing routine contains the following code,

Call pevent.Graphics.Clear(Color.FromArgb(255, 0, 0, 0))

Call pevent.Graphics.DrawImage(buttonMap, _
New Rectangle(0, 0, Width, Height), _
getCurrentFrameSourceRect(), _
GraphicsUnit.Pixel)

It seems that there is no way to clear the surface before redrawing as it
just comes out as black. How do I completely remove all colour
information from the back before redrawing? Ideally |I want to do this
all to a back buffer then redraw that, but at current I can't get it
working either way.

Thanks for any help in advance.

Nick.
"NickP" <a@a.comwrote in message
news:ef**************@TK2MSFTNGP02.phx.gbl...
>Hi again,

I've changed the transparent initialisation and moved it to the
CreateParams override,

Protected Overrides ReadOnly Property CreateParams() As
System.Windows.Forms.CreateParams
Get
Dim pCPsParams As CreateParams = MyBase.CreateParams()
pCPsParams.ExStyle = pCPsParams.ExStyle Or &H20
Return (pCPsParams)
End Get
End Property

I am also overriding OnPaintBackground so that no background is drawn.
Unfortunately I still get black bits...

Nick.

"NickP" <a@a.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
Hi there,

I have a usercontrol that inherits from Windows.Forms.Button.

In the OnCreateControl method I set the style of the control so that
it supports transparent backcolor and set the background color to
transparent.

....

Protected Overrides Sub OnCreateControl()
MyBase.OnCreateControl()
Call SetStyle(ControlStyles.SupportsTransparentBackColo r, True)
BackColor = Color.Transparent
End Sub
....

I have an image with magenta sections which I remove using
Bitmap.MakeTransparent(Color.Magenta). Unfortunately when I draw this
image onto the form the parts that were previously magenta, get drawn as
black.
My question is, how do I draw this image with the magenta parts as
transparent?
Many thanks in advance.
Nick.


Jul 11 '07 #4

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

Similar topics

2
by: Jaikumar | last post by:
Hi, 1) I have created one windows application, In the main form ( form1) i have added one usercontrol (usercontrol1), In that user control i am drawing one image. 2) In the UserControl1 i am...
3
by: Steve Koon | last post by:
Any thoughts on getting this project to work or suggesting another method would be appreciated. Steve ========================================== Project: A Windows Form which acts as a...
7
by: Peter Oliphant | last post by:
Using MakeTransparent one can supposedly turn a color used in a Bitmap to transparent. But, it looks to me like all it does it set these pixels to the color BackColor of the Control it's attached...
5
by: Mark Deibert | last post by:
I'm a former VB6 coder. Quit a few years ago. Now I'm back and trying to teach myself VB.NET. I don't remember having this much difficulty learning VB6. I'm totally stuck on something and need your...
4
by: Brian Henry | last post by:
I have an icon I want to draw onto the screen, but I want to streatch it out to be about 256x256 and make it about 75% transparent how would I go about this? do i need to convert it to a bitmap...
7
by: Martin | last post by:
I'm using the code show below (in VB.Net 2003) to create an image. I want to save this image to a .PNG file such that when I subsequently display it as part of a web page, the background of the...
5
by: Dale | last post by:
When I create a System.Drawing.Bitmap and save it as ImageType.GIF, how can I set the transparency so that the background is transparent. In my application, the Bitmap that I am working with has...
8
by: Brian Ward | last post by:
I am looking for a simple way to set the image transparency in a PictureBox. I have a moving PictureBox containing a graphic image .. moving by incrementing its Left property. The background...
0
by: MasterOfTheDark | last post by:
This one's a hairy one to explain. What I've got is a class called "VistaGroupBox" that I put some nice-looking Vista-style gradients in the background and made to look like the ribbon categories...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...

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.