0

我想使用标签模拟游戏菜单。我想要做的是当鼠标悬停在它上面时,字体会变大并且会改变字体颜色。在 Visual Basic 6.0 中是否有任何预先存在的代码可以仅使用数组来执行此操作?因为如果我手动进行,将花费大量时间。请帮我。

4

2 回答 2

0

您需要捕捉鼠标进入和离开事件。这是旧的,但您可以尝试使用 TrackMouseEvent API 来捕获鼠标事件。这是一个链接http://www.vbaccelerator.com/home/VB/Code/Libraries/Subclassing/Generating_MouseLeave_Events_for_a_Window/article.asp,其中包含一个实现 API 的类,并给出了使用它的示例。虽然这篇文章很旧,并且只讨论了它在 Win 95 之前的使用,因此您需要进行快速测试以查看它是否仍然受支持。

于 2012-09-27T15:29:03.800 回答
0

创建一个标签数组:在表单上放置一个标签,并为其指定索引 0,这将基本上创建一个包含 1 个标签的数组,然后您可以在代码中展开

'1 form with :
'    1 label : name=Label1    Index=0
Option Explicit

Private Sub Form_Load()
  Dim intIndex As Integer
  For intIndex = 1 To 4
    Load Label1(intIndex)
    Label1(intIndex).Visible = True
    Label1(intIndex).Caption = CStr(intIndex)
  Next intIndex
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  OnLabel False
End Sub

Private Sub Form_Resize()
  Dim intIndex As Integer
  Dim sngWidth As Single, sngHeight As Single
  Dim sngLblWidth As Single
  sngWidth = ScaleWidth
  sngHeight = ScaleHeight
  sngLblWidth = sngWidth / Label1.Count
  For intIndex = 0 To Label1.Count - 1
    Label1(intIndex).Move intIndex * sngLblWidth, 0, sngLblWidth
  Next intIndex
End Sub

Private Sub Label1_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
  OnLabel True
End Sub

Private Sub OnLabel(blnOn As Boolean)
  Dim intIndex As Integer
  Dim intSize As Integer
  Dim lngColor As Long
  If blnOn Then
    intSize = 20
    lngColor = vbRed
  Else
    intSize = 10
    lngColor = vbBlack
  End If
  For intIndex = 0 To Label1.Count - 1
    With Label1(intIndex)
      .FontSize = intSize
      .ForeColor = lngColor
    End With 'Label1(intIndex)
  Next intIndex
End Sub
于 2012-11-08T15:12:46.323 回答