Garry's Mod Wiki

DButton

Description

A standard Derma button.

By default, a DButton is 22px tall.

View source

Parent

Derives methods, etc not listed on this page from DLabel.

Implements

Implements or overrides the following hooks/methods. If you want to override these, you probably want to call the original function too.

Methods

We advise against using this. It may be changed or removed in a future update. An AccessorFunc that returns value set by DButton:SetDrawBorder. See that page for more info.
boolean DButton:IsDown()
Returns true if the DButton is currently depressed (a user is clicking on it).
DButton:SetConsoleCommand( string command, string args = nil )
Sets a console command to be called when the button is clicked. This overrides the button's DoClick method.
DButton:SetDrawBorder( boolean draw )
We advise against using this. It may be changed or removed in a future update. Does absolutely nothing at all. Default value is automatically set to true.
DButton:SetIcon( string img = nil )
Sets an image to be displayed as the button's background. Alias of DButton:SetImage
DButton:SetImage( string img = nil )
Sets an image to be displayed as the button's background. See DButton:SetMaterial for equivalent function that uses IMaterial instead. Also see: DImageButton
DButton:SetMaterial( IMaterial img = nil )
Sets an image to be displayed as the button's background. See DButton:SetImage for equivalent function that uses file paths instead. Also see DImageButton.
DButton:UpdateColours( table skin )
A hook called from within DLabel's PANEL:ApplySchemeSettings to determine the color of the text on display.

Example

The DButton is exactly what you think it is - a button!

local frame = vgui.Create( "DFrame" ) frame:SetSize( 300, 250 ) frame:Center() frame:MakePopup() local DermaButton = vgui.Create( "DButton", frame ) // Create the button and parent it to the frame DermaButton:SetText( "Say hi" ) // Set the text on the button DermaButton:SetPos( 25, 50 ) // Set the position on the frame DermaButton:SetSize( 250, 30 ) // Set the size DermaButton.DoClick = function() // A custom function run when clicked ( note the . instead of : ) RunConsoleCommand( "say", "Hi" ) // Run the console command "say hi" when you click it ( command, args ) end DermaButton.DoRightClick = function() RunConsoleCommand( "say", "Hello World" ) end
DButton.gif