Revision Difference
Panel:SetCommand#527966
<function name="SetCommand" parent="Panel" type="classfunc">
<description>
Sets the action signal command that's fired when a <page>Button</page> is clicked. The hook <page>PANEL:ActionSignal</page> is called as the click response.
This has no effect on buttons unless it has had its `AddActionSignalTarget` method called (an internal function not available by default in Garry's Mod LUA).
A better alternative is calling <page>Panel:Command</page> when a <page>DButton</page> is clicked.
</description>
<realm>Client</realm>
</function>
<example>
<description>Creates an engine-based <page>Frame</page> panel and changes the command that's fired when you click the white close button (by default the command is set to "Close").</description>
<description>Creates an engine-based <page>Frame</page> panel and changes the command that's fired when you click the white close button (by default the command is set to `Close`).</description>
<code>
-- Create a regular Frame panel
TestFrame = vgui.Create("Frame")
TestFrame:SetSize(200, 200)
local TestFrame = vgui.Create( "Frame" )
TestFrame:SetSize( 200, 200 )
TestFrame:Center()
TestFrame:MakePopup()
TestFrame:SetVisible(true)
local lbl = vgui.Create("DLabel", TestFrame)
lbl:Dock(FILL)
lbl:DockMargin(10, 10, 10, 10)
lbl:SetText("Click the white button in the upper right corner of this window.")
lbl:SetFont("ChatFont")
lbl:SetWrap(true)
TestFrame:SetVisible( true )
local lbl = vgui.Create( "DLabel", TestFrame )
lbl:Dock( FILL )
lbl:DockMargin( 10, 10, 10, 10 )
lbl:SetText( "Click the white button in the upper right corner of this window." )
lbl:SetFont( "ChatFont" )
lbl:SetWrap( true )
-- Create a background panel so we can see the Frame's internal buttons
local bg = vgui.Create("DPanel", TestFrame)
bg:Dock(FILL)
bg:SetBackgroundColor(Color(64, 64, 64, 192))
local bg = vgui.Create( "DPanel", TestFrame )
bg:Dock( FILL )
bg:SetBackgroundColor( Color( 64, 64, 64, 192 ) )
bg:MoveToBack()
-- Loop through Frame's internal components
for _, child in pairs(TestFrame:GetChildren()) do
for _, child in ipairs( TestFrame:GetChildren() ) do
-- Disable frame sizing
if(string.find(child:GetName(), "Grip")) then
⤶
if ( string.find( child:GetName(), "Grip" ) ) then
child:SetMouseInputEnabled(false)
-- Fire the "Testing" command when we click the white button⤶
elseif(child:GetName() == "frame_close") then⤶
⤶
child:SetCommand("Testing")⤶
⤶
-- Fire the "Testing" command when we click the white button⤶
elseif ( child:GetName() == "frame_close" ) then⤶
child:SetCommand( "Testing" )⤶
end
⤶
end⤶
⤶
function TestFrame:ActionSignal(signalName, signalValue)⤶
-- Show the signal name⤶
lbl:SetText("Received command: \""..signalName.."\"")⤶
⤶
end⤶
⤶
function TestFrame:ActionSignal( signalName, signalValue )⤶
⤶
-- Show the signal name⤶
lbl:SetText( "Received command: \"" .. signalName .. "\"" )
end
</code>
<output><image src="Panel_SetCommand_example1.gif"/></output>
⤶
</example></example>