各位大虾,我刚刚学习vb,现有两个问题需要您的回答:
一个问题关于图片框的:
    利用图片框控件来画点、线或者是圆,画完后能够借助与图片框显示,比如 Picture1.Line(200,200)-(500,500)。但是如果在运行阶段将显示结果最小化后,在将窗体还原,刚才在窗体中所显示的线就不见了,这是为什么?在窗体中绘图也是如此
 
第二个问题关于mousedown,mousemove和mouseup
     现在打算完成利用鼠标完成绘画功能,程序编制如下:以划线为例,程序如下:
Dim ax, ay, px, py As SinglePrivate Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 1 Then
        ax = X
        ay = Y
        px = X
        py = Y
    End If
End SubPrivate Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 1 Then
        Picture1.Line (ax, ay)-(X, Y)
    End If
End SubPrivate Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 1 Then
        Picture1.Line (ax, ay)-(X, Y)
    End If
End Sub窗体上只有一个图片框,但是结果好像不对,请帮助修正,,并给予代码注释。此外,在划线过程中是否是mousedown 和mousemove事件同时触发。

解决方案 »

  1.   

    第一个问题,设置picturebox的autoredraw=true看看。第二个问题,不要在mousemove事件中画线,因为这个事件在鼠标移动时会不断的被触发。
      

  2.   

    谢谢你,中海!
    第一个问题,我明白了;
    第二个问题,在划线的时候,mousemove事件是在不断的触发,那应当用什么方法。另外,我刚刚吧程序作了修改,程序代码如下:(在窗体中分别放置了一个图片框和四个单旋钮)
    Dim ax, ay, px, py As Single
    Dim Temp As Integer
    Private Sub Form_Load()
        ax = 0
        ay = 0
        px = 0
        py = 0
    End Sub
    Private Sub Option1_Click()
        Temp = 1
    End Sub
    Private Sub Option2_Click()
        Temp = 2
    End Sub
    Private Sub Option3_Click()
        Temp = 3
    End Sub
    Private Sub Option4_Click()
        Temp = 4
    End SubPrivate Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 1 Then
       ax = X
       ay = Y
    End If
    If Temp = 4 Then
       Picture1.CurrentX = X
       Picture1.CurrentY = Y
    End If
    End SubPrivate Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)'前半部分
    If Temp = 1 Then
       Picture1.Line (ax, ay)-(px, py)
    End If
    If Temp = 2 Then
       Picture1.Line (ax, ay)-(ax, py)
       Picture1.Line (ax, ay)-(px, ay)
       Picture1.Line (px, ay)-(px, py)
       Picture1.Line (ax, py)-(px, py)
    End If
    If Temp = 3 Then
       Picture1.Circle ((ax + px) / 2, (ay + py) / 2), 0.5 * Sqr((px - ax) ^ 2 + (py - ay) ^ 2)
    End If'后半部分If Button = 1 Then
       If Temp = 1 Then
          Picture1.Line (ax, ay)-(X, Y)
          px = X
          py = Y
       End If
       If Temp = 2 Then
          Picture1.Line (ax, ay)-(X, ay)
          Picture1.Line (ax, ay)-(ax, Y)
          Picture1.Line (ax, Y)-(X, Y)
          Picture1.Line (X, ay)-(X, Y)
          px = X
          py = Y
       End If
       If Temp = 3 Then
          Picture1.Circle ((ax + X) / 2, (ay + Y) / 2), 0.5 * Sqr((X - ax) ^ 2 + (Y - ay) ^ 2)
          px = X
          py = Y
       End If
       If Temp = 4 Then
          Picture1.Line -(X, Y)
          px = X
          py = Y
       End If
    End If
    End SubPrivate Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
     
     If Button = 1 Then
         If Temp = 1 Then
             Picture1.Line (ax, ay)-(X, Y)
         Else
           If Temp = 2 Then
             Picture1.Line (ax, ay)-(X, ay)
             Picture1.Line (ax, ay)-(ax, Y)
             Picture1.Line (ax, Y)-(X, Y)
             Picture1.Line (X, ay)-(X, Y)
           Else
            If Temp = 3 Then
              Picture1.Circle ((ax + X) / 2, (ay + Y) / 2), 0.5 * Sqr((X - ax) ^ 2 + (Y - ay) ^ 2)
            End If
           End If
         End If
         ax = 0
         ay = 0
         px = 0
         py = 0
      End If
    End Sub在修改后的程序中将form_load事件注释,将mousemove事件中的前半部分注释,将mouseup事件中的ax=0:ay=0:px=0:py=0,也注释得到的结果也不对,另外,如果将程序中的form_load事件和ax=0:ay=0:px=0:py=0进行注释,会发现划线的结果和刚才一样!
    希望你的答复,谢谢!
      

  3.   

    抱歉,这么长的代码我看着眼花。总之,在mousemove中尽量避免运行代码,尤其是耗时的动作,原因刚才说了,触发太频繁了。
    你只要在mousedown中记下起点,在mouseup时得到终点,画线连此两点就行。
      

  4.   

    只用mousedown和mouseup事件是可以实现,但是看不到轨迹呀。哈哈,不过还要谢谢你