By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,261 Members | 1,616 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,261 IT Pros & Developers. It's quick & easy.

Transparent Bitmap Drawn onto Transparent control

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.