DButton
Description
A standard Derma button.
By default, a DButton is 22px tall.
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.
Events
DButton:DoClick()
Called when the button is left clicked (on key release) by the player.
This will be called after DButton:IsDown.
See also DButton:DoRightClick.
DButton:DoRightClick()
Called when the button is right clicked (on key release) by the player.
See also DButton:DoClick.
Methods
boolean DButton:GetDrawBorder()
We advise against using this. It may be changed or removed in a future update.
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 )
Sets a console command to be called when the button is clicked.
This overrides the button's DoClick method.
DButton:SetDisabled( boolean disable )
We advise against using this. It may be changed or removed in a future update.
Use Panel:SetEnabled instead.
Sets whether or not the DButton is disabled.
When disabled, the button is greyed out and cannot be clicked.
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
Output: 
