타이틀바 없이 크기조절 및 상단 패널 만들어서 움직이게 하기(스티커,포스트잇 만들때)
메모장, 스티커, 포스트잇 만들때 기본 레이아웃
전체소스
아래 코딩
Public Class Form1
Dim First As Point
Private FormReSizeType As String = "None"
Private MoveMouseX As Integer ' 이동하기전 월래 마우스 X 위치
Private MoveMouseY As Integer ' 이동하기전 월래 마우스 Y 위치
'패널을 상단에 만들고 움직이게 함.
Private Sub Panel1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseDown
First = New Point( _
PointToScreen(e.Location).X - Me.Location.X, _
PointToScreen(e.Location).Y - Me.Location.Y _
) '폼의 위치와 현재 마우스 위치의 화면좌표 차를 First에 대입
End Sub
Private Sub Panel1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseMove
If e.Button = Windows.Forms.MouseButtons.Left Then '마우스 왼쪽 버튼을 누르고 있으면
Me.Location = New Point( _
PointToScreen(e.Location).X - First.X, _
PointToScreen(e.Location).Y - First.Y _
) '마우스 위치의 화면좌표에서 First를 뺀 값을 폼의 위치로 지정
End If
End Sub
Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
End Sub
Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
'클릭시 마우스 모양
If FormReSizeType <> "None" Then Exit Sub
MoveMouseX = e.X
MoveMouseY = e.Y
If e.Y >= 0 And e.Y < 5 And e.X >= 0 And e.X < 10 Then FormReSizeType = "TopLeft" : Me.Cursor = Cursors.SizeNWSE
If e.Y >= 0 And e.Y < 5 And e.X >= Me.Width - 10 And e.X <= Me.Width Then FormReSizeType = "TopRight" : Me.Cursor = Cursors.SizeNESW
If e.Y >= Me.Height - 5 And e.Y <= Me.Height And e.X >= 0 And e.X < 10 Then FormReSizeType = "BottomLeft" : Me.Cursor = Cursors.SizeNESW
If e.Y >= Me.Height - 5 And e.Y <= Me.Height And e.X >= Me.Width - 10 And e.X <= Me.Width Then FormReSizeType = "BottomRight" : Me.Cursor = Cursors.SizeNWSE
End Sub
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
If FormReSizeType = "None" Then
'이동중 커서 모양 설정
If e.Y >= 0 And e.Y < 10 And e.X >= 0 And e.X < 10 Then Me.Cursor = Cursors.SizeNWSE
If e.Y >= 0 And e.Y < 10 And e.X >= Me.Width - 10 And e.X <= Me.Width Then Me.Cursor = Cursors.SizeNESW
If e.Y >= Me.Height - 10 And e.Y <= Me.Height And e.X >= 0 And e.X < 10 Then Me.Cursor = Cursors.SizeNESW
If e.Y >= Me.Height - 10 And e.Y <= Me.Height And e.X >= Me.Width - 10 And e.X <= Me.Width Then Me.Cursor = Cursors.SizeNWSE
ElseIf e.Button = Windows.Forms.MouseButtons.Left Then
FromReSizeSet(e)
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub FromReSizeSet(ByVal e As System.Windows.Forms.MouseEventArgs)
'사이즈 조절하게 하기
Dim sX, sY As Integer
sX = MoveMouseX - e.X
sY = MoveMouseY - e.Y
If (FormReSizeType = "Top" Or FormReSizeType = "TopLeft" Or FormReSizeType = "TopRight") And Me.Height + sY > 25 Then
Me.Top = Me.Top - sY
Me.Height = Me.Height + sY
End If
If (FormReSizeType = "Bottom" Or FormReSizeType = "BottomLeft" Or FormReSizeType = "BottomRight") And Me.Height - sY > 25 Then
Me.Height = Me.Height - sY
MoveMouseY = e.Y '크기가 변하면 마우스의 위치가 변동 되기 때문에 다시 저장
End If
If (FormReSizeType = "Left" Or FormReSizeType = "TopLeft" Or FormReSizeType = "BottomLeft") And Me.Width + sX > 25 Then
Me.Left = Me.Left - sX
Me.Width = Me.Width + sX
End If
If (FormReSizeType = "Right" Or FormReSizeType = "TopRight" Or FormReSizeType = "BottomRight") And Me.Width - sX > 25 Then
Me.Width = Me.Width - sX
MoveMouseX = e.X '크기가 변하면 마우스의 위치가 변동 되기 때문에 다시 저장
End If
End Sub
Private Sub Form1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.MouseLeave
Me.Cursor = Cursors.Default
FormReSizeType = "None"
End Sub
Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
If FormReSizeType <> "None" And e.Button = Windows.Forms.MouseButtons.Left Then
FromReSizeSet(e)
FormReSizeType = "None"
End If
End Sub
End Class
출처: http://byhwan.tistory.com/entry/타이틀바-없는-form-크기조정하기?category=535198 [By Hwan]
'VB.net' 카테고리의 다른 글
다른창 띠위서 그래프 그리기(MSChart이용) (0) | 2018.03.19 |
---|---|
테두리가 없는 폼이동 (0) | 2018.03.19 |
실시간 알람 공지 (0) | 2018.03.19 |
시스템 상대경로 (0) | 2018.03.19 |
FTP 파일전송 (0) | 2018.03.19 |