Garry's Mod Wiki



An image button.

This panel inherits all methods of DButton, such as DLabel:DoClick.

View source


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


This is used internally - although you're able to use it you probably shouldn't. Used internally to briefly scale the image when clicked.
boolean DImageButton:GetDepressImage()
Returns whether DImageButton:DepressImage is functional or not.
string DImageButton:GetImage()
Returns the "image" of the DImageButton. Equivalent of DImage:GetImage.
boolean DImageButton:GetStretchToFit()
Returns whether the image inside the button should be stretched to fit it or not See DImageButton:SetStretchToFit
DImageButton:SetColor( table color )
Sets the color of the image. Equivalent of DImage:SetImageColor
DImageButton:SetDepressImage( boolean enable )
Controls whether DImageButton:DepressImage is functional or not.
We advise against using this. It may be changed or removed in a future update. Alias of DImageButton:SetImage.
DImageButton:SetImage( string strImage, string strBackup = nil )
Sets the "image" of the DImageButton. Equivalent of DImage:SetImage.
DImageButton:SetImageVisible( boolean visible )
Hides or shows the image of the image button. Internally this calls Panel:SetVisible on the internal DImage.
DImageButton:SetKeepAspect( boolean keep )
Sets whether the DImageButton should keep the aspect ratio of its image. Equivalent of DImage:SetKeepAspect. Note that this will not try to fit the image inside the button, but instead it will fill the button with the image.
DImageButton:SetMaterial( IMaterial mat )
Sets a Material directly as an image. Equivalent of DImage:SetMaterial.
DImageButton:SetOnViewMaterial( string mat, string backup )
See DImage:SetOnViewMaterial
DImageButton:SetStretchToFit( boolean stretch )
Sets whether the image inside the DImageButton should be stretched to fill the entire size of the button, without preserving aspect ratio. If set to false, the image will not be resized at all.


The DImageButton is the same as the DImage, but you can click it. When you hover over it, you will get the default link cursor on Windows.

local frame = vgui.Create( "DFrame" ) frame:SetSize( 300, 250 ) frame:Center() frame:MakePopup() local DermaImageButton = vgui.Create( "DImageButton", frame ) DermaImageButton:SetPos( 25, 50 ) -- Set position -- DermaImageButton:SetSize( 16, 16 ) -- OPTIONAL: Use instead of SizeToContents() if you know/want to fix the size DermaImageButton:SetImage( "icon16/bomb.png" ) -- Set the material - relative to /materials/ directory DermaImageButton:SizeToContents() -- OPTIONAL: Use instead of SetSize if you want to resize automatically ( without stretching ) DermaImageButton.DoClick = function() MsgN( "You clicked the image!" ) end