タイトル | : Re^5: マウスでラベルに線を引きたい |
記事No | : 10764 |
投稿日 | : 2012/04/02(Mon) 15:44 |
投稿者 | : shu |
これでどうですか? 合ってますか?
label1:Autosize=false,Text = ""
Private Label1Down As Boolean = False Private x1 As Integer = -1 Private x2 As Integer = -1 Private drawcol As Color
Private Sub Label1_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseDown Label1Down = True x1 = e.X Label1.Refresh() End Sub
Private Sub Label1_MouseMove(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseMove If Label1Down Then x2 = e.X drawcol = Color.Cyan Label1.Refresh() End If End Sub
Private Sub Label1_MouseUp(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseUp Label1Down = False drawcol = Color.Blue Label1.Refresh() End Sub
Private Sub Label1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Label1.Paint Dim g = e.Graphics g.Clear(Label1.BackColor) If x1 >= 0 AndAlso x2 >= 0 Then Using brs As New SolidBrush(drawcol) Dim crec = Label1.ClientRectangle Dim dx1 = Math.Min(x1, x2) Dim dx2 = (x1 + x2) - dx1 g.FillRectangle(brs, dx1, crec.Top, dx2 - dx1, crec.Height) End Using End If End Sub
|