KenMillard
Board Regular
- Joined
- Apr 25, 2007
- Messages
- 151
Excel 2003
I have a macro that uses the hittest method to return an item from the listview. In order for this to work, I need to multiple the x and y values by a certain number. It used to be 15. After changing the resolution (and dpi) of my monitor, 15 no longer works.
I could figure out what the new number is easily enough, what I need to do is determine the correct number programmatically so it will work on multiple machines, regardless of resolution or screen dpi.
Is this possible?
Once I figure out how to determine the correct multiplier for the hittest, I'll need to change how I determine which column was clicked.
If it helps, the purpose of this is to set the from and to page when printing inspection reports. The list view displays each operation as a list item with a from page column and a to page column. Right clicking decreases the page numbers and left clicking increases the page numbers. If there's a better way to do this, let me know.
Thanks
Ken
I have a macro that uses the hittest method to return an item from the listview. In order for this to work, I need to multiple the x and y values by a certain number. It used to be 15. After changing the resolution (and dpi) of my monitor, 15 no longer works.
I could figure out what the new number is easily enough, what I need to do is determine the correct number programmatically so it will work on multiple machines, regardless of resolution or screen dpi.
Is this possible?
Code:
Private Sub ListView_Operations_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As stdole.OLE_XPOS_PIXELS, ByVal y As stdole.OLE_YPOS_PIXELS)
Dim CurrItem As ListItem
Dim PageCount As Long
If Me.ListView_Operations.ListItems.Count = 0 Then Exit Sub
Set CurrItem = ListView_Operations.HitTest(x * 15, y * 15)
PageCount = CurrItem.Tag
Select Case x
Case 275 To 360 ' From Page Column
If Button = 2 Then ' right click
If CLng(CurrItem.ListSubItems(1)) > 1 Then
CurrItem.ListSubItems(1).Text = CurrItem.ListSubItems(1) - 1
End If
ElseIf Button = 1 Then ' left click
If CLng(CurrItem.ListSubItems(1)) < CLng(CurrItem.ListSubItems(2)) Then
CurrItem.ListSubItems(1).Text = CurrItem.ListSubItems(1) + 1
End If
End If
Case Is > 370 'To Page Column
If Button = 2 Then ' right click
If CLng(CurrItem.ListSubItems(2)) > CLng(CurrItem.ListSubItems(1)) Then
CurrItem.ListSubItems(2).Text = CurrItem.ListSubItems(2) - 1
End If
ElseIf Button = 1 Then ' left click
If CLng(CurrItem.ListSubItems(2)) < PageCount Then
CurrItem.ListSubItems(2).Text = CurrItem.ListSubItems(2) + 1
End If
End If
End Select
End Sub
Once I figure out how to determine the correct multiplier for the hittest, I'll need to change how I determine which column was clicked.
If it helps, the purpose of this is to set the from and to page when printing inspection reports. The list view displays each operation as a list item with a from page column and a to page column. Right clicking decreases the page numbers and left clicking increases the page numbers. If there's a better way to do this, let me know.
Thanks
Ken