Garry's Mod Wiki

Panel:SetFGColor

  Panel:SetFGColor( number r or color, number g, number b, number a )

Description

Sets the foreground color of a panel.

For a Label or RichText, this is the color of its text.

This function calls Panel:SetFGColorEx internally.

Please note that for most panels the engine will overwrite the foreground and background colors a frame after panel creation via the PANEL:ApplySchemeSettings hook, so you may want to set the color in that hook instead.

See Panel:SetBGColor for the background color.

This doesn't apply to all VGUI elements (such as DLabel) and its function varies between them

Arguments

1 number r or color
The red channel of the color, or a Color. If you pass the latter, the following three arguments are ignored.
2 number g
The green channel of the color.
3 number b
The blue channel of the color.
4 number a
The alpha channel of the color.

Example

Creates a Label and sets its text color to white.

local label = vgui.Create( "Label" ) label:SetFGColor( Color( 255, 255, 255, 255 ) )

Example

Sets the foreground color of a RichText to match the chat box format.

-- Create a window frame TextFrame = vgui.Create("DFrame") TextFrame:SetSize(200, 50) TextFrame:Center() TextFrame:SetTitle("This is a color test") TextFrame:MakePopup() -- RichText panel local richtext = vgui.Create("RichText", TextFrame) richtext:Dock(FILL) -- Sample text richtext:SetText("Here is some light green text.") -- When the panel is ready for layout, make the text light green function richtext:PerformLayout() self:SetFGColor(Color(153, 255, 153)) end
Output: