BUG: ListView Control's Left and Top Properties Return Unexpected Values (240944)
The information in this article applies to:
- Microsoft Visual Basic Learning Edition for Windows 6.0
- Microsoft Visual Basic Professional Edition for Windows 6.0
- Microsoft Visual Basic Enterprise Edition for Windows 6.0
This article was previously published under Q240944 SYMPTOMS
When the Left or Top property of the ListView control is assigned a negative value, the result is a value greater by 1 pixel. Positive values return the expected result.
RESOLUTIONStep-by-Step Workaround- Start a new Standard EXE project in Visual Basic. Form1 is created by default.
- On the Project menu, click to select Components, check Microsoft Windows Common Controls 6.0, and then click OK.
- Draw a ListView control on Form1. On the Properties window, set View = 0 - lvwSmallIcon.
- Add the following code to the General Declarations section of Form1:
Option Explicit
Dim itm As ListItem
Private Sub Form_Click()
Dim sngLeft As Single
Dim sngTop As Single
Me.ScaleMode = vbPixels
sngLeft = -2
sngTop = -2
Set itm = ListView1.ListItems.Add(Text:="item")
' Inaccurate
itm.Left = sngLeft
itm.Top = sngTop
MsgBox "Left = " & itm.Left & " Top = " & itm.Top
' More accurate
LocateListItems itm, sngLeft, sngTop
MsgBox "Left = " & itm.Left & " Top = " & itm.Top
End Sub
Private Sub LocateListItems(item As ListItem, x As Single, y As Single)
Select Case x
Case Is < -1.5
x = x - 1
Case Is < 0
x = x - 1.1
Case Else
End Select
item.Left = x
Debug.Print "Item.Left = "; item.Left
Select Case y
Case Is < -1.5
y = y - 1
Case Is < 0
y = y - 1.1
Case Else
End Select
item.Top = y
Debug.Print "Item.Top = "; item.Top
End Sub
- Run the project by pressing the F5 key, and note the results in the Immediate window. Without correction, the inaccurate result is displayed. After a call to the correcting function, the more accurate result is displayed.
STATUSMicrosoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.
Modification Type: | Major | Last Reviewed: | 5/12/2003 |
---|
Keywords: | kbBug kbCmnCtrls kbCtrl kbListView kbpending kbSample KB240944 |
---|
|