Microsoft KB Archive/240944

= BUG: ListView Control's Left and Top Properties Return Unexpected Values =

Article ID: 240944

Article Last Modified on 5/12/2003

-

APPLIES TO


 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



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.



Step-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.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

<div class="moreinformation_section">

MORE INFORMATION
Because these properties are for positions that are stored as real numbers, they are usually not whole numbers. However, for any negative value that is assigned, the result is always 1 pixel greater than the assigned value.

Steps to Reproduce Behavior
 Start a new Standard EXE project in Visual Basic. Form1 is created by default.</li> On the Project menu, click to select Components, check Microsoft Windows Common Controls 6.0, and then click OK.</li> Draw a ListView control on Form1. On the Properties window, set View = lvwSmallIcon.</li>  Add the following code to the General Declarations section of Form1: Private Sub Form_Click ListView1.ListItems(1).Left = -5 Debug.Print "Left = "; ListView1.ListItems(1).Left ListView1.ListItems(1).Top = -5 Debug.Print "Top = "; ListView1.ListItems(1).Top End Sub

Private Sub Form_Load Me.ScaleMode = vbPixels Call ListView1.ListItems.Add(Text:="item") End Sub </li> Run the project by pressing F5, click on the form, and note that this produces the following output in the Immediate window: Left = -3.968504

Top = -3.968504

</li> Note that the result is 1 pixel greater than the assigned value.</li></ol>

Keywords: kbbug kblistview kbcmnctrls kbsample kbctrl kbpending KB240944

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.