Visual Basic 中学校 掲示板 投稿の管理
タグのない投稿を抽出
統計
RSS
Visual Basic 中学校
投稿一覧
マウスを動かしながら直線を引きたい
この投稿へのリンク
https://keijiban.umayadia.com/ThreadDetail.aspx?ThreadId=286#CommentId1950
この投稿の削除
削除パスワード
削除する
コメント本文
投稿者
ヴァン
 (社会人)
投稿日時
2009/2/6 02:59:52
まあ、お遊び程度ならこんな感じでどうですか。
Public Class Form1
Private startX, starty, endx, endy As Integer
Private axisList As List(Of Axis) = New List(Of Axis)
Private Sub PictureBox1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
If e.Button = Windows.Forms.MouseButtons.Left Then
startX = e.X
startY = e.Y
End If
End Sub
Private Sub PictureBox1_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
Dim lineAxis As Axis = New Axis
lineAxis.StartPoint.X = startX
lineAxis.StartPoint.Y = starty
lineAxis.EndPoint.X = endx
lineAxis.EndPoint.Y = endy
axisList.Add(lineAxis)
PictureBox1.Invalidate()
End Sub
Private Sub PictureBox1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
If e.Button = Windows.Forms.MouseButtons.Left Then
endx = e.X
endy = e.Y
PictureBox1.Invalidate()
End If
End Sub
Private Sub PictureBox1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
e.Graphics.DrawLine(Pens.Red, startX, starty, endx, endy)
For Each lineAxis As Axis In axisList
e.Graphics.DrawLine(Pens.Blue, lineAxis.StartPoint, lineAxis.EndPoint)
Next
End Sub
End Class
Public Class Axis
Public StartPoint As Point
Public EndPoint As Point
End Class