Garry's Mod Wiki

Panel:SetBGColor

  Panel:SetBGColor( number r, number g, number b, number a )
  Panel:SetBGColor( table color )

Description

Sets the background color of a panel such as a RichText, Label, DColorCube or the base Panel.

For many panels, such as DLabel and Panel, you must use Panel:SetPaintBackgroundEnabled( true ) for the background to appear.

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:SetFGColor for the foreground color.

This doesn't apply to all VGUI elements and its function varies between them

Default Arguments

1 number r
The red channel of the color.
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.

Argument Overload: Use color object

1 table color
A Color object/table to read the color from. This is slower than providing four numbers. You could use Color:Unpack to address this. You should also cache your color objects if you wish to use them, for performance reasons.

Example

Creates a RichText panel that mimics a blue screen of death.

-- Create a window frame TextFrame = vgui.Create("DFrame") TextFrame:SetSize(300, 100) TextFrame:Center() TextFrame:SetTitle("Windows XP Blue Screen") TextFrame:MakePopup() -- RichText panel local richtext = vgui.Create("RichText", TextFrame) richtext:Dock(FILL) -- Sample text richtext:SetText("A problem has been detected and Windows has been shut down to prevent damage to your computer.\n\nMOTHERBOARD_FRIED") -- When the panel is ready for layout, set the background color to blue function richtext:PerformLayout() self:SetBGColor(Color(0, 0, 255)) end
Output: