TextBox 前景属性 (权限)TextBox.ForeColor property (Access)

前景色 属性用于指定控件中的文本的颜色。You can use the ForeColor property to specify the color for text in a control. 读/写 LongRead/write Long.

语法Syntax

表达式前景色expression.ForeColor

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

备注Remarks

可以对窗体或报表中的控件使用此属性,以使它们更易于读取或传递某种特殊的含义。You can use this property for controls on forms or reports to make them easy to read or to convey a special meaning. 例如, 当 "库存量" 控件中的值低于再订购级别时, 您可以更改该文本的颜色。For example, you can change the color of the text in the UnitsInStock control when its value falls below the reorder level.

您可以在报表上使用此属性来创建特殊的视觉效果,使用彩色打印机进行打印时。You can also use this property on reports to create special visual effects when you print with a color printer. 当使用报表上,此属性指定 打印 方法的打印和绘图颜色。When used on a report, this property specifies the printing and drawing color for the Print, Line, and Circle methods.

前景色 属性包含数值表达式,表示控件中的文本颜色的值。The ForeColor property contains a numeric expression that represents the value of the text color in the control.

您可以使用 "颜色生成器" 来设置该属性, 方法是在属性表中的属性框的右侧选择 "生成" 按钮。You can use the Color Builder to set this property by choosing the Build button to the right of the property box in the property sheet. 使用颜色生成器还可以定义控件中文本的自定义颜色。Using the Color Builder enables you to define custom colors for text in controls.

您可以通过使用控件的默认控件样式或 Visual Basic 中的**DefaultControl** 属性来设置此属性的默认值。You can set the default for this property by using a control's default control style or the DefaultControl property in Visual Basic.

对于报表,可以设置 属性,只需通过使用宏或 Visual Basic 事件过程中节的 OnPrint 事件属性设置指定。For reports, you can set the Circle property only by using a macro or a Visual Basic event procedure specified in a section's OnPrint event property setting.

示例Example

以下示例根据 txtPastDue 文本框的值,使用 RGB 函数来设置 BorderColorBackColorForeColor 属性。The following example uses the RGB function to set the BorderColor, BackColor, and ForeColor properties depending on the value of the txtPastDue text box. 你也可以使用 QBColor 函数来设置这些属性。You can also use the QBColor function to set these properties. 将下面的代码放在Form_Current () 事件中会在用户打开窗体或移动到新记录时立即设置控件的显示特征。Putting the following code in the Form_Current( ) event sets the control display characteristics as soon as the user opens a form or moves to a new record.

Sub Form_Current() 
 Dim curAmntDue As Currency, lngBlack As Long 
 Dim lngRed As Long, lngYellow As Long, lngWhite As Long 
 
 If Not IsNull(Me!txtPastDue.Value) Then 
 curAmntDue = Me!txtPastDue.Value 
 Else 
 Exit Sub 
 End If 
 lngRed = RGB(255, 0, 0) 
 lngBlack = RGB(0, 0, 0) 
 lngYellow = RGB(255, 255, 0) 
 lngWhite = RGB(255, 255, 255) 
 If curAmntDue > 100 Then 
 Me!txtPastDue.BorderColor = lngRed 
 Me!txtPastDue.ForeColor = lngRed 
 Me!txtPastDue.BackColor = lngYellow 
 Else 
 Me!txtPastDue.BorderColor = lngBlack 
 Me!txtPastDue.ForeColor = lngBlack 
 Me!txtPastDue.BackColor = lngWhite 
 End If 
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.