读书人

大家帮小弟我看看picturebox的有关问题

发布时间: 2012-01-20 18:53:53 作者: rapoo

大家帮我看看picturebox的问题,不知道那里错了
Private Sub pic1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pic1.MouseDown


If e.Button = Windows.Forms.MouseButtons.Left Then
If Not shoulddrawLine Then
Pstart = New Point(e.X, e.Y)
shoulddrawLine = True
Else
Pend = New Point(e.X, e.Y)
Call drawline1(Pstart, Pend) 我想在pic1中操作 在pic2中画出线段
shoulddrawLine = False
End If
End If
End Sub
Private Sub drawline1(ByVal mpoint1 As Point, ByVal mpoint2 As Point)
Pic2.Enabled = True
mpoint1.Y = mpoint1.Y + 250 pic1和pic2的x左边都一样 Y值相差250
mpoint2.Y = mpoint2.Y + 250
Pic2.CreateGraphics.DrawLine(Pens.Blue, mpoint1, mpoint2)结果没有在pic2中画出线段
Microsoft.VisualBasic.MsgBox("yong le de ") 此语句会运行
End Sub 大家帮我看看怎么错了啊

[解决办法]
mpoint1.Y = mpoint1.Y + 250 pic1和pic2的x左边都一样 Y值相差250
mpoint2.Y = mpoint2.Y + 250
把这两句删除就可以了,这里的x,y只相对于pic1,pic2,而非窗体下的绝对位置。

[解决办法]
Private Sub drawline1(ByVal mpoint1 As Point, ByVal mpoint2 As Point)
Pic2.Enabled = True
'mpoint1.Y = mpoint1.Y + Pic1.Height
'mpoint2.Y = mpoint2.Y + Pic1.Height
'测试鼠标的位置。
'MsgBox("pic2.Location.X: 0" & "-" & Pic2.Width & vbCrLf & _
' "pic2.Location.Y: 0" & "-" & Pic2.Height & vbCrLf & _
' "mpoint1.X: " & mpoint1.X & vbCrLf & _
' "mpoint1.Y: " & mpoint1.Y & vbCrLf & _
' "mpoint2.X: " & mpoint2.X & vbCrLf & _
' "mpoint2.Y: " & mpoint2.Y & vbCrLf)
Pic2.CreateGraphics.DrawLine(Pens.Blue, mpoint1, mpoint2)
End Sub

读书人网 >VB Dotnet

热点推荐