i am try to make border less form' it's work fine. but i cant add "Aero Snap" property for it. i am try different method for make borderless form. but they are not resize smoothly. that method is only best way for smooth resize. i want it maximize when it drag upper side of screen. how i did that here is my whole code.
Imports System.Runtime.InteropServices
Public Class Form2
<DllImport("user32.dll&")>
Public Shared Function ReleaseCapture() As Boolean
End Function
<DllImport("user32.dll&")>
Public Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
End Function
Private Const HTCAPTION As Integer = 2
Private Const WM_NCLBUTTONDOWN As Integer = &HA1
Protected Overrides ReadOnly Property CreateParams As CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
cp.Style = cp.Style Or &H20000 '<;--- Minimize borderless form from taskbar
Return cp
End Get
End Property
Private Sub Form1_MouseDown(sender As Object, e As MouseEventArgs) Handles Me.MouseDown
If locked = True Then
locked = False
Exit Sub
End If
If direction_ = ResizeDirection.None Then
ElseIf direction_ = ResizeDirection.title Then
MoveForm()
Else
ResizeForm()
End If
End Sub
Private Sub MoveForm()
ReleaseCapture()
SendMessage(Me.Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0)
Invalidate()
End Sub
Private Sub ResizeForm()
' mouse_down = True
ReleaseCapture()
SendMessage(Me.Handle, WM_NCLBUTTONDOWN, direction_, 0)
End Sub
Dim frame_width As Integer = 3
Dim title_width As Integer = 31
Public Enum ResizeDirection
None = 0
title = 1
Left = 10
TopLeft = 13
Top = 12
TopRight = 14
Right = 11
BottomRight = 17
Bottom = 15
BottomLeft = 16
End Enum
Dim direction_ As ResizeDirection
Dim locked As Boolean = False
Private Sub Form1_MouseMove(sender As Object, e As MouseEventArgs) Handles Me.MouseMove
If Me.WindowState = FormWindowState.Maximized Then
If e.Y < title_width Then
direction_ = ResizeDirection.title
Else
direction_ = ResizeDirection.None
End If
Cursor = Cursors.Default
Exit Sub
End If
If e.Y < frame_width Then
If e.X < frame_width Then
Cursor = Cursors.SizeNWSE
direction_ = ResizeDirection.TopLeft
ElseIf e.X > Me.Width - frame_width Then
Cursor = Cursors.SizeNESW
direction_ = ResizeDirection.TopRight
Else
Cursor = Cursors.SizeNS
direction_ = ResizeDirection.Top
End If
ElseIf e.Y > Me.Height - frame_width Then
If e.X < frame_width Then
Cursor = Cursors.SizeNESW
direction_ = ResizeDirection.BottomLeft
ElseIf e.X > Me.Width - frame_width Then
Cursor = Cursors.SizeNWSE
direction_ = ResizeDirection.BottomRight
Else
Cursor = Cursors.SizeNS
direction_ = ResizeDirection.Bottom
End If
ElseIf e.X < frame_width Then
Cursor = Cursors.SizeWE
direction_ = ResizeDirection.Left
ElseIf e.X > Me.Width - frame_width Then
Cursor = Cursors.SizeWE
direction_ = ResizeDirection.Right
Else
If e.Y < title_width Then
direction_ = ResizeDirection.title
Else
direction_ = ResizeDirection.None
End If
Cursor = Cursors.Default
End If
End Sub
Private Sub BTN_MINIMIZE_Click(sender As Object, e As EventArgs) Handles BTN_MINIMIZE.Click
Me.WindowState = FormWindowState.Minimized
End Sub
Private Sub BTN_MAXIMIZE_Click(sender As Object, e As EventArgs) Handles BTN_MAXIMIZE.Click
' Dim Hd As Integer = 6
If Me.WindowState = FormWindowState.Maximized Then
Me.WindowState = FormWindowState.Normal
' Panel_TITLE.Height -= Hd
' BTN_MINIMIZE.Top -= Hd
' BTN_MAXIMIZE.Top -= Hd
' BTN_CLOSE.Top -= Hd
' SplitContainer1.Top -= Hd
' SplitContainer1.Height -= Hd
Else
' Me.ControlBox = True
Me.WindowState = FormWindowState.Maximized
' Me.ControlBox = False
' Panel_TITLE.Height += Hd
' BTN_MINIMIZE.Top += Hd
' BTN_MAXIMIZE.Top += Hd
' BTN_CLOSE.Top += Hd
' SplitContainer1.Top += Hd
' SplitContainer1.Height += Hd
End If
End Sub
Private Sub BTN_CLOSE_Click(sender As Object, e As EventArgs) Handles BTN_CLOSE.Click
Application.Exit()
End Sub
'===============================================================================================================
<DllImport("user32.dll", EntryPoint:="FindWindowEx")>
Public Shared Function FindWindowEx(ByVal hwndParent As IntPtr, ByVal hwndChildAfter As IntPtr, ByVal lpszClass As String, ByVal lpszWindow As String) As IntPtr
End Function
<DllImport("User32.dll")>
Public Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal uMsg As Integer, ByVal wParam As Integer, ByVal lParam As String) As Integer
End Function
Private Sub Form1_Resize(sender As Object, e As EventArgs) Handles Me.Resize
' TextBox1.Text = Cursor.Position.ToString + "%%%"
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.FormBorderStyle = FormBorderStyle.None
Me.ControlBox = False
Me.BackColor = SystemColors.ControlDark
Me.ResizeRedraw = True
Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
Dim rrr As Rectangle = Screen.FromRectangle(Me.Bounds).WorkingArea
rrr.Width += 18
rrr.Height -= 1
Me.MaximumSize = rrr.Size
End Sub
Private Sub Form1_Move(sender As Object, e As EventArgs) Handles Me.Move
If Me.Top = 0 Then
ReleaseCapture()
SendMessage(Me.Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0)
' Invalidate()
locked = True
Else
locked = False
End If
End Sub
End Class