I'm having trouble for a while and I decided to bring this up here because I can't find a nice solution for this ugly flickering in my WinForms.
I made a borderless form and use this code to make the form draggable and resizable on every edges and corner.
Public Class Form2
Private Const WM_NCHITTEST As Integer = &H84
Private Const WM_MOUSEMOVE As Integer = &H200
Private Const WM_LBUTTONDOWN As Integer = &H201
Private Const WM_LBUTTONUP As Integer = &H202
Private Const MK_LBUTTON As Integer = &H1
Private Const HTLEFT As Integer = &HA
Private Const HTRIGHT As Integer = &HB
Private Const HTTOP As Integer = &HC
Private Const HTTOPLEFT As Integer = &HD
Private Const HTTOPRIGHT As Integer = &HE
Private Const HTBOTTOM As Integer = &HF
Private Const HTBOTTOMLEFT As Integer = &H10
Private Const HTBOTTOMRIGHT As Integer = &H11
Private OffSet As Point = Point.Empty
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.FormBorderStyle = FormBorderStyle.None
End Sub
Protected Overrides Sub WndProc(ByRef m As Message)
If m.Msg = WM_NCHITTEST Then
Dim loc As New Point(m.LParam.ToInt32 And &HFFFF, m.LParam.ToInt32 >> 16)
loc = PointToClient(loc)
Dim bTop As Boolean = (loc.Y < ClientRectangle.Y + 4)
Dim bLeft As Boolean = (loc.X < ClientRectangle.X + 4)
Dim bRight As Boolean = (loc.X > Width - 4)
Dim bBottom As Boolean = (loc.Y > Height - 4)
If bTop And bLeft Then
m.Result = CType(HTTOPLEFT, IntPtr)
Return
ElseIf bTop And bRight Then
m.Result = CType(HTTOPRIGHT, IntPtr)
Return
ElseIf bBottom And bLeft Then
m.Result = CType(HTBOTTOMLEFT, IntPtr)
Return
ElseIf bBottom And bRight Then
m.Result = CType(HTBOTTOMRIGHT, IntPtr)
Return
ElseIf bLeft Then
m.Result = CType(HTLEFT, IntPtr)
Return
ElseIf bTop Then
m.Result = CType(HTTOP, IntPtr)
Return
ElseIf bRight Then
m.Result = CType(HTRIGHT, IntPtr)
Return
ElseIf bBottom Then
m.Result = CType(HTBOTTOM, IntPtr)
Return
End If
ElseIf m.Msg = WM_LBUTTONDOWN Then
OffSet = New Point(MousePosition.X - Me.Location.X, MousePosition.Y - Me.Location.Y)
ElseIf m.Msg = WM_MOUSEMOVE AndAlso m.WParam.ToInt32 = MK_LBUTTON Then
Me.Location = New Point(MousePosition.X - OffSet.X, MousePosition.Y - OffSet.Y)
End If
MyBase.WndProc(m)
End Sub
End Class
Then I discovered when playing around with the form that the
right side is flickering when you are resizing it from the left same with top and bottom. If I resize the form from the top the bottom part is flickering. The dragging is perfect no problem at all just this resizing.
What I have tried:
Now, I thought it was all because of the code that I'm using. So I added another form to my project with no controls in it just the default form with borders and run it, to my surprise the ugly flickering is now present there. Now I'm really pissed off, I don't what the hell did just happened. If I can't find a solution for this I'm gonna uninstall visual studio and reinstall it.