本文介绍了油漆问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用鼠标直接在表单上绘制直线
How do I draw straight lines directly on to the form using the mouse
推荐答案
由于问题是有限的,甚至不包含问号,并且问题中不需要其他任何内容,因此没有其他内容.
Since the question is limited, doesn't even contain question mark, and nothing else is desired in the question then nothing else is provided.
但是,就像用铅笔画图一样,通常需要擦除,或者不做擦除之类的事情.
But like drawing with pencil typically erasing is desired or un doing or whatever.
Option Strict On
Public Class Form1
Dim LinePoints As New List(Of Point())
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.DoubleBuffered = True
Me.Location = New Point(CInt((Screen.PrimaryScreen.WorkingArea.Width / 2) - (Me.Width / 2)), CInt((Screen.PrimaryScreen.WorkingArea.Height / 2) - (Me.Height / 2)))
End Sub
Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
e.Graphics.PixelOffsetMode = Drawing2D.PixelOffsetMode.Half
If LinePoints.Count > 0 Then
For i = 0 To LinePoints.Count - 1
e.Graphics.DrawLine(Pens.Black, LinePoints(i)(0), LinePoints(i)(1))
Next
End If
If LMouseDown = True AndAlso MouseMoving = True Then
e.Graphics.DrawLine(Pens.Black, BeginPoint, MouseMovingPoint)
End If
End Sub
Dim LMouseDown As Boolean = False
Dim MouseMoving As Boolean = False
Dim BeginPoint As Point
Dim MouseMovingPoint As Point
Private Sub Form1_MouseDown(sender As Object, e As MouseEventArgs) Handles Me.MouseDown
If e.Button = Windows.Forms.MouseButtons.Left Then
BeginPoint = New Point(e.X, e.Y)
LMouseDown = True
End If
End Sub
Private Sub Form1_MouseMove(sender As Object, e As MouseEventArgs) Handles Me.MouseMove
If LMouseDown = True Then MouseMoving = True
MouseMovingPoint = New Point(e.X, e.Y)
Me.Refresh()
End Sub
Private Sub Form1_MouseUp(sender As Object, e As MouseEventArgs) Handles Me.MouseUp
If LMouseDown = True AndAlso MouseMoving = True Then
LinePoints.Add({BeginPoint, New Point(e.X, e.Y)})
LMouseDown = False
MouseMoving = False
ElseIf LMouseDown = True Then
LMouseDown = False
End If
Me.Refresh()
End Sub
End Class
这篇关于油漆问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!