热情软件屋

 

如何做到鼠标下移时,窗体变大,鼠标上移时,窗体变小


编号:QA004652
建立日期: 2002年12月8日 最后修改日期:2002年12月8日
所属类别:

livefreely5168:
    我是一个VB的初学者,想做一个这样的程序:鼠标下移时,窗体变大,鼠标上移时,窗体变小,程序如下:
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Static a As Integer, b As Integer
    If X > a And Y > b Then
    Form1.Width = Form1.Width + 10
    Form1.Height = Form1.Height + 10
    Else
    Form1.Width = Form1.Width - 10
    Form1.Height = Form1.Height - 10
    End If
    a = X
    b = Y
    End Sub
    

    可为什么做出来不是想要的效果?我实在找不出问题,请各位专家多多指教,感激不尽!!!

回答:

    问题关键处于你的IF语句,首先,Width和Height不可用一条IF语句来控制,必须分开。其次,你忽略了 X=a 和 Y=b 的情况,这种情况下,Width或Height是不需要变动的。 正确的写法如下:
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Static a As Integer, b As Integer
     If X > a Then
     Form1.Width = Form1.Width + 10
     ElseIf X < a Then
     Form1.Width = Form1.Width - 10
     End If
     If Y > b Then
     Form1.Height = Form1.Height + 10
     ElseIf Y < b Then
     Form1.Height = Form1.Height - 10
     End If
     a = X
     b = Y
    End Sub
    

此问题由林水财回答。

 
把这个问题推荐给朋友
   
   
您的意见类别
您的名字
您的电子邮件
您的建议(请尽可能详细)
 
 

版权所有 1997-2008 热情软件屋
如果您有任何建议和意见, 请给我发个电子邮件 askpro@china-askpro.com
Web Designed by ZebraStudio