Microsoft KB Archive/213479

= XL2000: Controls in a Dialog Box May "Snap" to Preset Values =

Article ID: 213479

Article Last Modified on 11/23/2006

-

APPLIES TO


 * Microsoft Excel 2000 Standard Edition

-



This article was previously published under Q213479





SYMPTOMS
In Microsoft Excel, when you use Microsoft Visual Basic commands to adjust the dimensions of controls in custom dialog boxes by manipulating the Top, Left, Height, and Width properties of the controls, the controls always snap to certain numbers. For example, if you change the Left property of a control, it always snaps to a multiple of 0.75.



CAUSE
This behavior occurs because of the design of the custom dialog box system.



MORE INFORMATION
Snapping occurs when a control is placed in a certain position that is not precisely supported in a custom dialog box. For example, the Left property of a control always snaps to the next lowest multiple of 0.75. If you change the Left property of a control to any of the following values, the Left property snaps to the indicated value:   When .Left        It snaps is set to this value      to this value 0                         0   0.25                       0   0.50                       0   0.75                       0.75   1.00                       0.75   1.25                       0.75   1.50                       1.50 If you try to set the Left property of a control to 1.12 or 1.25, for example, Microsoft Excel snaps the control's Left property to 0.75, because that is the greatest multiple of 0.75 less than or equal to 1.12 or 1.25.

In addition, if one property is changed by snapping, it may affect other related properties. For instance, in the Visual Basic code example below, an edit box is created with a Top value of 50 and a Height value of 15. The Top value initially snaps to 49.5; however, when the Height value snaps, the Top value changes to 47.25, even though 49.5 is a valid Top value. The Left and Width values are similarly related. The final Top, Left, Height, and Width values are always valid, but controls may move slightly because of snapping. Listed here are the guidelines that Excel uses when determining how a control property snaps.

NOTE: The values in Excel 2000 may vary slightly from the following values, but the behavior is the same.   Control type       Units snapped to   --- All Controls      The Left property of all controls snaps to the nearest multiple of 0.75 less than or equal to the indicated value.

The Top property of all controls snaps to the nearest multiple of 0.75 less than or equal to the indicated value.

Edit boxes        The Height property of edit boxes and labels uses and labels        the following table to determine the true Height value:

Height set to  Height snaps to                      --- 0.00 - 18.50   13.50                      18.75 - 28.25   23.25                      28.50 - 38.00   33.00                      38.25 - 47.75   42.75

For subsequent ranges, add 9.75 for each range.

The Width property of edit boxes and labels snaps to                     the nearest multiple of 0.75 less than or equal to                      the indicated value.

Buttons           The Height property of buttons snaps to the nearest multiple of 0.75 less than or equal to the indicated value, but no less than 15.75.

The Width property of buttons snaps to the nearest multiple of 0.75 less than or equal to the indicated value, but no less than 3.00.

Dialog box frame  All properties of a dialog frame snap to the nearest multiple of 0.75 less than or equal to the indicated value.

Group boxes       The Height property of group boxes snaps to the nearest multiple of .75 less than or equal to the indicated value, but no less than 18.75.

The Width property of group boxes snaps to the nearest multiple of 0.75 less than or equal to the indicated value, but no less than 23.25.

Check boxes       The Height property of check boxes is always 16.50.

The Width property of check boxes snaps to the nearest multiple of 0.75 less than or equal to the indicated value, but no less than 23.25.

Option buttons    The Height property of option buttons is always 16.50.

The Width property of option buttons snaps to the nearest multiple of 0.75 less than or equal to the indicated value, but no less than 23.25.

List boxes        The Height property of list boxes uses the following table to determine the true Height value:

Height set to  Height snaps to                      --- 0.00 - 26.75   21.75                      27.00 - 36.50   31.50                      36.75 - 46.25   41.25                      46.50 - 56.00   51.00

For subsequent ranges, add 9.75 for each range.

The Width property of list boxes snaps to the nearest multiple of 0.75 less than or equal to the indicated value, but no less than 12.00.

Drop-down lists   The Height property of drop-down lists is always 15.00.

The Width property of drop-down lists snaps to the nearest multiple of 0.75 less than or equal to the indicated value, but no less than 12.00.

Drop-down edit    The Height property of drop-down edit boxes is always boxes             13.50.

The Width property of drop-down edit boxes snaps to                     the nearest multiple of 0.75 less than or equal to                      the indicated value, but no less than 12.00.

Scroll bars       The Height property of scroll bars snaps to the nearest multiple of 0.75 less than or equal to the indicated value, but no less than 12.00.

The Width property of scroll bars is always 12.00.

Spinners          The Height property of spinners snaps to the nearest multiple of 0.75 less than or equal to the indicated value, but no less than 13.50.

The Width property of spinners is always 9.00.

Visual Basic Code Example
Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Partner or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Partners, please visit the following Microsoft Web site:

https://partner.microsoft.com/global/30000104

For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:

http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS

The following subroutine creates a new dialog sheet, adds an edit box to it, changes the Top, Left, Height, and Width properties of the edit box, and then displays what the various properties have snapped to. Sub ControlSnapDemo 'Add a new dialog sheet to the active workbook. Set DemoDlg = ThisWorkbook.DialogSheets.Add 'Add an edit box to the current dialog sheet. The dimensions 'supplied are arbitrary. Set EdBox = DemoDlg.EditBoxes.Add(50, 50, 50, 50) 'Set the Top, Left, Height, and Width properties of the edit box. EdBox.Top = 50 EdBox.Left = 70 EdBox.Height = 15 EdBox.Width = 80 'Construct a message string which will be shown in a message box. 'Chr$(9) is a tab character: Chr$(10) is a line feed. MsgString = Chr$(9) & "Original Setting" & Chr$(9) & "Snaps To" MsgString = MsgString & Chr$(10) & "Top" & Chr$(9) & "50" & Chr$(9) MsgString = MsgString & Chr$(9) & EdBox.Top & Chr$(10) & "Left" MsgString = MsgString & Chr$(9) & "70" & Chr$(9) & Chr$(9) MsgString = MsgString & EdBox.Left & Chr$(10)& "Height" & Chr$(9) MsgString = MsgString & "15" & Chr$(9) & Chr$(9) & EdBox.Height MsgString = MsgString & Chr$(10) & "Width" & Chr$(9) & "80" & Chr$(9) MsgString = MsgString & Chr$(9) & EdBox.Width 'Show the message. MsgBox MsgString End Sub When you run this subroutine, a new dialog sheet containing a new edit box is created. You receive the following message:   Original setting   Snaps to  - Top     50        49.5 Left    70        69.75 Height  15        15 Width   80        79.5 The properties of the edit box have snapped to values appropriate for an edit box.

Additional query words: XL2000

Keywords: kbprb kbprogramming KB213479

-

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

© Microsoft Corporation. All rights reserved.