I have a borderless form that has a transparent background. I only wanted
the color that I painted the background with to be transparent and not the
controls on the form or the box I draw in the middle of the form. The
problem I am having is when I pass another window
in front of it or drag the window, it doesn’t repaint with the transparent
background. It just shows the drag marks of the window that I dragged in
front of it. The other thing I noticed was if I do an invalidate() it just
gets darker and eventual it will because a solid color again.
This is my code that I am using:
Private Sub DoubleBuffering_Paint(ByVal sender As Object, _
ByVal e As PaintEventArgs) Handles MyBase.Paint
Dim g As Graphics '= e.Graphics
Dim Dw As Bitmap
Dw = New Bitmap(Me.Width, Me.Height, e.Graphics)
g = Graphics.FromImage(Dw)
g.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
DrawRoundedForm(0, _
0, _
Me.Width, _
Me.Height, _
18, _
Me.Region)
'filling the main background
Dim cl As New SolidBrush(Color.FromArgb(100, Color.Black))
g.FillRectangle(cl, New RectangleF(0, 0, Me.Width, Me.Height))
cl.Dispose()
Dim c2 As New SolidBrush(Color.WhiteSmoke) 'draw solid background
g.FillRectangle(c2, New RectangleF(15, 15, Me.Width - 30, Me.Height
- 30))
c2.Dispose()
'draw border
Dim pn As New Pen(Color.Black, 1.5) 'this pen will be 3 pixels wide
g.DrawRectangle(pn, 15, 15, Me.Width - 30, Me.Height - 30) 'draw a
rectangle in Pixel mode (the default)
pn.Dispose()
e.Graphics.DrawImageUnscaled(Dw, 0, 0)
g.Dispose()
End Sub
Protected Overrides Sub OnPaintBackground(ByVal pevent As
System.Windows.Forms.PaintEventArgs)
'prevents flickering on background redraw, does not redraw the
background
'MyBase.OnPaintBackground(pevent)
End Sub
Any body have any ideas?
Is it better to pain the backgroun on the form in a bitmap then draw what I
have above on top ot the bitmap.
If so how can I get it to run smoothly while being dragged or having a
window dragged infront of it.