Garry's Mod Wiki

DImageButton

Description

An image button.

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

Parent

Derives from DButton.

Methods

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:SetIcon()
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 )
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.

Example

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() 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() Msg( "You clicked the image!" ) end

Page Links


Special Pages


Wikis

?

Render Time: 136ms

DB GetPage 55
Generate Html 6
SaveChanges (1) 52
Render Body 0
Render Sidebar 19