feesu
asked on
VB6 - How to create a Label Array at runtime and trigger its events?
Hi Experts,
I have the following code that is trying to fill the values of the recordset into labels that should appear under eachother neatly. And then I want the label to be underlined (like hyperlinks) with a pointer cursor when a mouse comes over it. And upon clicking on it, I want it to perform an action.
However, I failed to Dim WithEvents for unknown reason!
Please correct my code, or recommend otherwise!
I have the following code that is trying to fill the values of the recordset into labels that should appear under eachother neatly. And then I want the label to be underlined (like hyperlinks) with a pointer cursor when a mouse comes over it. And upon clicking on it, I want it to perform an action.
However, I failed to Dim WithEvents for unknown reason!
Please correct my code, or recommend otherwise!
....
If Not (RS.BOF And RS.EOF) Then
RS.MoveFirst
Dim LBL() As Label
For i = 1 To RS.RecordCount
ReDim Preserve LBL(i)
With LBL1(i)
.Caption = RS("FormCaption")
.Left = 0
.Top = LBL(i - 1).Top + LBL(i - 1).Height
.Visible = True
End With
RS.MoveNext
Next
End If
....
Private Sub LBL_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
Me.LBL(Index).FontUnderline = True
Screen.MouseIcon = vbArrow
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Roland,
I'm sorry, it was my mistake. I had defined the label twice. It works fine now.
Left is how to make the label caption underlined on mouse over with a pointer cursor and with no decoration on mouse out. I can't seem to have my code working for that!
I'm sorry, it was my mistake. I had defined the label twice. It works fine now.
Left is how to make the label caption underlined on mouse over with a pointer cursor and with no decoration on mouse out. I can't seem to have my code working for that!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Roland,
This mouseMove code, unfortunately didn't work! It doesn't change neither the font nor the cursor.
This mouseMove code, unfortunately didn't work! It doesn't change neither the font nor the cursor.
Check the code again. It must work. It the label array name is "LBL", the it must work.
ASKER
The label name is now lbl_FormCaption, and I have changed it in my code but it didn't work. See below plz.
Private Sub lbl_FormCaption_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
If lbl_FormCaption(Index).MousePointer <> vbCustom Then
lbl_FormCaption(Index).MousePointer = vbCustom
lbl_FormCaption(Index).MouseIcon = LoadPicture("c:\windows\cursors\harrow.cur") 'Or the icon or cursor that you want
lbl_FormCaption(Index).FontUnderline = True
End If
Dim k As Integer
For k = lbl_FormCaption.LBound To lbl_FormCaption.UBound
If lbl_FormCaption(k).MousePointer = vbCustom Then
lbl_FormCaption(k).MousePointer = vbDefault
lbl_FormCaption(k).FontUnderline = False
End If
Next k
End Sub
The second part of the routine (starting with the line "Dim k as integer") must not be in lbl_FormCaption_MouseMove, but in Form_MouseMove, as I mentioned in the original message. Try that.
ASKER
Hi Roland,
It works fine now. Thanks alot.
It works fine now. Thanks alot.
ASKER
Roland!
Why is it that I'm not able to change the cursor image to another one in the same C:\Windows\Cursors folder??
I have tried aero_link.cur and many others, but it always gived me "invalid picture" !!
Why is it that I'm not able to change the cursor image to another one in the same C:\Windows\Cursors folder??
I have tried aero_link.cur and many others, but it always gived me "invalid picture" !!
None of the aero* will work. You'll probably using Windows Vista (as Aero is the codebase name of the graphical subsystem of Vista), and Vista cursors are in more advanced format than VB6 (and ancient program) can support. Only old cursor formats will work in VB6. It's a casuality than harrow.cur has keeped the same format in all versions of Windows. If you wish to use other cursor, try searching the Internet.
ASKER
I get the following error on this line:
Subscript out of range >>> Load LBL(i) 'Load a new element of you array. Element 0 has been created at design time