SizeToFit 方法 (权限)Label.SizeToFit method (Access)

您可以使用SizeToFit方法调整控件的大小, 使其适应它所包含的文本或图像。You can use the SizeToFit method to size a control so that it fits the text or image that it contains.

语法Syntax

表达式SizeToFitexpression.SizeToFit

_表达式_一个代表**Label** 对象的变量。expression A variable that represents a Label object.

备注Remarks

例如,可以将 SizeToFit 方法应用规模太小,在其 标题 属性中显示的所有文本的命令按钮。For example, you can apply the SizeToFit method to a command button that is too small to display all the text in its Caption property.

您可以应用 SizeToFit 方法对仅在窗体设计视图中的控件或报表设计视图。You can apply the SizeToFit method to controls only in form Design view or report Design view.

SizeToFit方法使控件变大或变小, 具体取决于它所包含的文本或图像的大小。The SizeToFit method makes a control larger or smaller, depending on the size of the text or image that it contains.

与新控件的大小,您必须在代码中创建的 CreateControl 方法,可以结合使用 SizeToFit 方法。You can use the SizeToFit method in conjunction with the CreateControl method to size new controls that you have created in code.

备注

[!注释] 通过 SizeToFit 方法就可以调整大小并不是所有的控件包含文本或图像。Not all controls that contain text or an image can be sized by the SizeToFit method. 多个控件绑定到数据可以变化的大小从一条记录到下一步。Several controls are bound to data that can vary in size from one record to the next. 这些控件包括文本框、 列表框、 组合框和绑定的对象框控件。These controls include the text box, list box, combo box, and bound object frame controls. SizeToFit 方法不适用于控件在数据访问页。The SizeToFit method does not apply to controls on data access pages.

示例Example

下面的示例在窗体上创建一个新窗体和一个命令按钮。The following example creates a new form and a command button on the form. 该过程然后设置控件的 标题 属性和控件的大小以容纳标题。The procedure then sets the control's Caption property and sizes the control to fit the caption.

Sub SizeNewControl() 
 Dim frm As Form, ctl As Control 
 
 ' Create new form. 
 Set frm = CreateForm 
 ' Create new command button. 
 Set ctl = CreateControl(frm.Name, _ 
 acCommandButton, , , , 500, 500) 
 ' Restore form. 
 DoCmd.Restore 
 ' Set control's Caption property. 
 ctl.Caption = "Extremely Long Control Caption" 
 ' Size control to fit caption. 
 ctl.SizeToFit 
End Sub

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.