[vb.net] 주어진 비율을 유지하면서 마우스로 사각형을 그립니다 > vb.net

본문 바로가기

vb.net

[Mouse] [vb.net] 주어진 비율을 유지하면서 마우스로 사각형을 그립니다

회원사진
하나를하더라도최선을
2021-01-30 09:39 4,825 0

본문



   Dim mRect As Rectangle
    Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
        mRect = New Rectangle(e.X, e.Y, 00)
        Me.Invalidate()
    End Sub
 
    Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
        If e.Button = Windows.Forms.MouseButtons.Left Then
            mRect = New Rectangle(mRect.Left, mRect.Top, e.X - mRect.Left, e.Y - mRect.Top)
            'Replace 1.5 with the scale you want to use
            Dim hgt As Integer = Convert.ToInt32(mRect.Height / 1.5)
            Dim wdth As Integer = Convert.ToInt32(mRect.Width / 1.5)
            mRect.Size = New Size(wdth * 1.5, hgt * 1.5)
            Me.Invalidate()
        End If
    End Sub
 
    Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
        Using pen As New Pen(Color.Red, 3)
            e.Graphics.DrawRectangle(pen, mRect)
        End Using
    End Sub

댓글목록0

등록된 댓글이 없습니다.
게시판 전체검색