Garry's Mod Wiki

DLabel:DoClick

  DLabel:DoClick()

Description

Called when the label is left clicked (on key release) by the player.

This will be called after DLabel:OnDepressed and DLabel:OnReleased.

This can be overridden; by default, it calls DLabel:Toggle.

See also DLabel:DoRightClick, DLabel:DoMiddleClick and DLabel:DoDoubleClick.

Example

Creates a label in the center of the screen, that prints I was clicked! to the console and disappears when clicked.

local lbl = vgui.Create( "DLabel" ) -- Creates our label lbl:SetFont( "DermaLarge" ) lbl:SetText( "Click me!" ) lbl:SizeToContents() lbl:Center() lbl:SetMouseInputEnabled( true ) -- We must accept mouse input function lbl:DoClick() -- Defines what should happen when the label is clicked print("I was clicked!") self:Remove() end
Output:
I was clicked!

When the label is clicked.