Why my borderless form is flickering when resizing from top and left?

  • Thread starter Thread starter lelouch_vi
  • Start date Start date
L

lelouch_vi

Guest
hi I saw this code to resize and move my borderless form.

I saw this code here by IronRazerz. This is good I'm searching for something like this for a while now, all I can see in other site are tutorial made for c#. May I know if there are other drawback by using this? One more thing the form is flickering when I'm resizing it from top or left but if I resized it from right or bottom it's good, just like a normal form. I don't what could be the problem since honestly, I don't understand what is written below. It seems that it uses some hex values.

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

Continue reading...
 
Back
Top