vb.net Form flickering black - vb.net

The form shows many black boxes, I don't paint any graphics, I also removed the background image and it is still flickering.
I used double buffer and used this code below too
Protected Overloads Overrides ReadOnly Property CreateParams() As CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
cp.ExStyle = cp.ExStyle Or 33554432
Return cp
End Get
End Property
all this reduced the flickering but it still happens and leaves these black boxes. and it happens when I scroll in a flowpanel too.
I also want to use a background image, so I need something that will work with it too.

Related

How to prevent WinForms app from flickering

I found the following code which cancels the flickering in a WinForms application:
Protected Overrides ReadOnly Property CreateParams() As CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
cp.ExStyle = cp.ExStyle Or &H2000000
Return cp
End Get
End Property 'CreateParams
The issue comes when "minimizing and maximizing the form, all controls are invisible. Removing &H2000000 fix the problem, but the controls start to flicker" like it says in this comment on this question.
There's any update or way to solve this?

how to make user controls transparent

I have migrated a userControl from vb6 to vb.net, and i have problem with it's transparency.
in vb6, the property backstyle was used to make the control transparent, but in vb.net, i can't find it.
is there any equivalent for this property?
After some searches on the internet I found this pearl:
Protected Overrides ReadOnly Property CreateParams() As CreateParams
Get
' Make background transparent
Dim cp As CreateParams = MyBase.CreateParams
cp.ExStyle = cp.ExStyle Or &H20
Return cp
End Get
End Property
Protected Overrides Sub OnPaintBackground(e As PaintEventArgs)
'' call MyBase.OnPaintBackground(e) only if the backColor is not Color.Transparent
If Me.BackColor <> Color.Transparent Then
MyBase.OnPaintBackground(e)
End If
End Sub
I've tested it and it seems to be working fine.

Impossible clean PictureBox

I want clean the PictureBox image, so I make this code: TransparentPictureBox.Image = Nothing, the image don't disappear and I obtain all new image overlapping to the previous. How can I fix this?
I stay using a custom control, this is the class:
Public Class TransparentPictureBox
Inherits PictureBox
Public Sub New()
Me.SetStyle(ControlStyles.Opaque, True)
Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, False)
End Sub
Protected Overrides ReadOnly Property CreateParams() As System.Windows.Forms.CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
cp.ExStyle = cp.ExStyle Or &H20 ' Turn on WS_EX_TRANSPARENT
Return cp
End Get
End Property
End Class
The control is working exactly as you designed it.
With the ControlStyles.Opaque option set to True, it does not draw its background:
If true, the control is drawn opaque and the background is not painted.
When you set the Image property to Nothing, you're expecting it to be emptied.
How does a PictureBox draw itself though? It first draws the background color, then it draws the image on top of that. Since you've disabled background painting, though, the background doesn't get drawn and the previous image doesn't get erased.
Why do you have that option set? Remove it if that is not the behavior you're looking for.
Just write this although this not optimal solution but it will work
picturebox1.imagelocation = ""

VB Setting up a click-through but visible windows form

I have a form which is set to TopMost. It is basically a gaming tool which runs in-game and only accepts key bindings. Now, I need to disable all click events in the form and making "Click-through" so that the users will not be interrupted when they accidentally click or right-click the form. If I will not use a click-through form, clicking events will focus the form which shows the taskbar and makes the game slow. I'll just use a key binding to enable/disable that click-through feature. How do you set this in a Windows form using VB.Net?
Override CreateParams() in your Form and set the WS_EX_TRANSPARENT flag:
Public Class Form1
Private Const WS_EX_TRANSPARENT As Integer = &H20
Protected Overrides ReadOnly Property CreateParams() As System.Windows.Forms.CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
cp.ExStyle = cp.ExStyle Or WS_EX_TRANSPARENT
Return cp
End Get
End Property
End Class
This will give the "Click-through" functionality that you're looking for.

Transparent control backgrounds on a VB.NET gradient filled form?

I'm filling the background of some VB.NET 2005 WinForms form with a nice pretty gradient fill (by overriding the OnPaint event). This works fine but the various labels etc on the form show with a solid background even after I set the BackColor to Color.Transparent. Setting the transparency key of the form itself seems to affect this but I cannot get the labels to have a truely transparent BackColor, is there an easy way to get around this or am I looking at custom controls etc?
Add a new class to your project and paste the code shown below. Build. Drop the new control from the top of your toolbox onto your form.
Public Class TransparentLabel
Inherits Label
Public Sub New()
Me.SetStyle(ControlStyles.Opaque, True)
Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, False)
End Sub
Protected Overrides ReadOnly Property CreateParams() As System.Windows.Forms.CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
cp.ExStyle = cp.ExStyle Or &H20 ' Turn on WS_EX_TRANSPARENT
Return cp
End Get
End Property
End Class
The flicker might be noticeable, no fix.
After some experimentation I've found that the following works for gradiant filling form backgrounds and preserving label transparency:
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
Dim formGraphics As Graphics = e.Graphics
Dim gradientBrush As New LinearGradientBrush(New Point(0, Height), New Point(0, 0), Me.AppSettings.FormGradiantFrom, Me.AppSettings.FormGradiantTo)
formGraphics.FillRectangle(gradientBrush, ClientRectangle)
End Sub
And in the form load event:
SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.DoubleBuffer Or _
ControlStyles.ResizeRedraw Or ControlStyles.UserPaint, True)