TextBox.ForeColor 屬性 (Access)TextBox.ForeColor property (Access)

您可以使用 ForeColor 屬性指定控制項文字的色彩。You can use the ForeColor property to specify the color for text in a control. 可讀寫的 LongRead/write Long.



_運算式_代表**TextBox** 物件的變數。expression A variable that represents a TextBox object.


您可以使用表單或報表中控制項的該屬性,讓控制項更易於讀取或傳遞特殊的意義。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. 在報表上時,這個屬性會指定 列印線條Circle 方法列印和繪圖色彩。When used on a report, this property specifies the printing and drawing color for the Print, Line, and Circle methods.

ForeColor 屬性包含一個數值運算式,代表控制項中之文字色彩的值。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 事件屬性設定所指定設定 Circle 屬性。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.


下列範例會根據 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 
 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 
 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.