Transparent Bitmap Drawn onto Transparent control

  • Thread starter Thread starter NickP
  • Start date Start date
N

NickP

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.SupportsTransparentBackColor, 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.
 
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.

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.SupportsTransparentBackColor, 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.
 
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.
 
Hi again,

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

Nick.
 
Back
Top