用vb.net 写一个屏幕画框的程序
Public Class Form1
Dim m_IsMouseDown As Boolean = False
Dim m_StartPoint As Point
Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
m_IsMouseDown = True
m_StartPoint = New Point(e.X, e.Y)
End Sub
Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
If (m_IsMouseDown) Then '如果鼠标左键按下,则绘制图形
Dim g As Graphics = Me.CreateGraphics() '创建Graphics对象
g.DrawRectangle(Pens.Blue, _ '绘制一个蓝色的方框
Math.Min(m_StartPoint .X, e .X), _ '左上角X坐标
Math .Min (m_StartPoint .Y ,e .Y), _ '左上角Y坐标
Math .Abs (e .X -m _StartPoint .X ) , _ '宽度:取两点之间的绝对值
Math .Abs (e .Y -m _StartPoint .Y )) '高度:取两点之间的绝对值
g = Nothing '释放Graphics对象所占用的内存区域
End If
End Sub
Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System
创作工场
免责声明:
以上内容除特别注明外均来源于网友提问,创作工场回答,未经许可,严谨转载。
点击这里>>使用🔥专业版,更聪明、更完整、更原创!