|
Adding Interactivity To A User Control When developing a Graph User Control in Visual Basic 5 for a client, I was asked to provide a event on the control which would return the data index as the mouse moved across the control. As a graphical user control has only dumb line and print objects, there was no special event that I could use to provide this feature. So I created one using the following techniques.
In the user control, make a public event as follows Public Event ucMouseMove() Now add a MouseMove subroutine to the control Private Sub UserControl_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) Dim i As Integer ' Define which graph column the user is pointing at GrafDataId = 0 For i = dataRowsMaxRows To 1 Step -1
Check the current position of the mouse against an array that holds the X axis positions of the different objects in the graph If X > grafX(i) Then ' Set the plot indexes and raise the event that can be trapped by the control holding the user control GrafDataId = i RaiseEvent ucMouseMove Exit Sub End If Next i GrafDataId = 0 End Sub And now set a property for the user control as follows Public Property Get GrafDataPos () As Variant GrafDataPos = GrafDataId End Property Now in the form holding the user control, you will be able to add the new event for the control
Private Sub myGraph1_ucMouseMove ' Find the current index of a bar in a graph by using the following code MsgBox " Index " & myGraph1.GrafDataPos End Sub Where GrafDataPos is a property of the graph that holds the current position of the graph
|
|
Links >>> Home | Search | Workbench | Orders | Newsletter | Access Security | Access professionals |