Hi,
Here is another link that might help.
http://msdn.microsoft.com/library/de...lStudioNET.asp
Here is some sample code.
Public Class UserControl1
Inherits System.Windows.Forms.UserControl
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
SetStyle(ControlStyles.SupportsTransparentBackColo r, True)
'Add any initialization after the InitializeComponent() call
Me.BackColor = Color.Transparent
End Sub
'UserControl1 overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
components = New System.ComponentModel.Container()
End Sub
#End Region
Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs)
Dim g As Graphics = e.Graphics
Dim bm As New Bitmap(Me.Width, Me.Height)
Dim gBm As Graphics = Graphics.FromImage(bm)
gBm.FillRectangle(Brushes.Blue, 0, 0, Me.Width, Me.Height)
gBm.FillEllipse(Brushes.Red, 0, 0, Me.Width, Me.Height)
gBm.FillRectangle(Brushes.Blue, 50, 50, 20, 20)
bm.MakeTransparent(Color.Blue)
g.DrawImage(bm, 0, 0)
End Sub
End Class
Ken
---------------------
"Grahammer" <po********@127.0.0.1> wrote in message
news:em**************@TK2MSFTNGP11.phx.gbl...
Is it possible to set the background of a usercontrol as transparent?
I tried setting the background image of the usercontrol to a transparent
GIF, but that caused MAJOR problems.
I'm making some controls that aren't rectangular and it won't be pretty if
I end up with a grey rectangle behind each one.
http://msdn.microsoft.com/library/en...asp?frame=true
This link says that it should be simple to create a usercontrol with a
transparent background, and Herfried has suggested the same, but the
control still has a grey background. Basically I'm creating a button with four
images (normal, mouseover, pushed and disabled) and I want the transparent
parts of the image to show the form/controls/etc. that are below the
button. This will allow for round, oval or any other shaped button that I can
draw. The code is done and working, except for this transparency issue.
To test I've done the following:
- Created a new UserControl
- Added the following two lines to the Public Sub New() subroutine (I'm
assuming that this is the "constructor" that is mentioned in the MSDN
support page)
- Save all files
- Did a build on the control
- Added the control to a Form.
- Ran the project.
...the user control is still "control" grey and is not transparent...
Why is this happening? I didn't have this problem when using VB6. Is there
a work around?