I need a method that sets the background of the ElementHost completely transparent or so that it does not even render in the first place.
Current Structure
In the background I have a PictureBox.
Over that there is my UserControl (Which you can Download below).
Both the PictureBox and the UserControl have a Width of 150.
As you can see in the Picture above, the UserControl is 100% Invisible.
In the UserControl is an ElementHost with a Width of 120, within that there is a WPF-Content with a Width of 100.
Everything is Transparent, except the ElementHost1.
My Code
UserControl:
Protected Overrides ReadOnly Property CreateParams() As System.Windows.Forms.CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
cp.ExStyle = &H20
Return cp
End Get
End Property
Protected Overrides Sub OnPaintBackground(ByVal e As System.Windows.Forms.PaintEventArgs)
End Sub
Public Overrides Sub Refresh()
Parent.Invalidate(New Rectangle(Me.Location, Me.Size), True)
End Sub
Public Sub New()
InitializeComponent()
Me.SetStyle(ControlStyles.SupportsTransparentBackColor, True)
Me.BackColor = System.Drawing.Color.Transparent
ElementHost1.BackColor = System.Drawing.Color.Transparent
ElementHost1.BackColorTransparent = True
End Sub
I´ve also tried to create a Custom ElementHost:
Public Class TransElementHost
Inherits ElementHost
Public Sub TransElementHost()
Me.SetStyle(ControlStyles.SupportsTransparentBackColor, True)
Me.BackColorTransparent = True
'Me.BackColor = System.Drawing.Color.FromArgb(0, 0, 0, 0)
End Sub
Protected Overrides ReadOnly Property CreateParams() As System.Windows.Forms.CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
cp.ExStyle = &H20
Return cp
End Get
End Property
Protected Overrides Sub OnPaintBackground(ByVal e As System.Windows.Forms.PaintEventArgs)
End Sub
Public Overrides Sub Refresh()
Parent.Invalidate(New Rectangle(Me.Location, Me.Size), True)
End Sub
End Class
Does anybody have an idea?
It's probably not the best fix, but you could try using the
ButtonRenderer
class. Put this code either inOnPaintBackground
orOnPaint
.The
ButtonRenderer
class is used to draw the regular buttons; their border, background, text, image etc.I used the above code myself to create a custom control with transparent background. (Though I see now that my control inherits from
ButtonBase
... But the above code is still worth a try).