From GMod Wiki
Function |
Syntax |
DButton:SetDisabled( Boolean disabled ) |
Description: |
True disables the buttons, so it can't be clicked. False enables it. |
Returns: |
nil |
In Object: |
DButton |
Realm: |
|
BBCode Link: |
[b][url=http://wiki.garrysmod.com/?title=DButton.SetDisabled]DButton.SetDisabled [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] |
Examples
Description | Creates a frame with a button, that when pressed will disable itself. |
Used on | |
Code |
// Lets set up the frame we're gonna be using for this example.
OurFrame = vgui.Create( "DFrame" ) // Just setting up a DFrame for the example. This is the window that'll hold it
OurFrame:SetSize( 200, 200 ) // Size of the window. 200x200 pixels
OurFrame:SetTitle( "Random window!" ) // Setting the title of the window to "Random Window!"
// And now for the button.
ClickyButton = vgui.Create("DButton", OurFrame) // Creating our button, and parenting it to the frame we just created.
ClickyButton:SetText("Click me!") // Setting the text of the button to "Click Me!". This is what will be written on the button.
ClickyButton:SetSize( 100, 20 ) // Setting the size, 100x20
ClickyButton:SetPos( 50, 90 ) // Settings the buttons position relative to its parent (The frame). This should be right in the middle.
ClickyButton.DoClick = function ( CliclyButton) // This is the function that will be run when the button is pressed.
ClickyButton:SetDisabled( true ) // Disable the button so it can't be pressed again
ClickyButton:SetText( "You clicked me!" ) // Set the button text to "You clicked me!", now that the user has clicked it.
end
|
Output | N/A |
Setting disabled to true doesn't prevent the DoClick method from running. You can check if the button is disabled in DoClick using GetDisabled( )
See Also