Code |
Frame = vgui.Create("DFrame") -- make a frame
Frame:SetSize(150, 75)
Frame:Center() -- places the frame in the center of your screen
Frame:SetTitle( "Frame Title" )
Frame:MakePopup() -- activates the cursor so you can click stuff
button = vgui.Create("DButton", Frame) -- create a DButton, parent it to Frame
button.Colour = Color(100, 100, 100, 255) -- Assign The Button This Variable, So We Can Change The Colour Without Having A Complex Paint Function.
button:SetText( "Press Me" ) -- initial text on the button
button:SetPos(5, 25) -- position relative to the frames top left corner
button:SetSize( 100, 25 ) -- set the buttons dimentions
button.Paint = function()
surface.SetDrawColor(button.Colour) -- anything we draw will be the colour saved in button.Colour
surface.DrawRect(0, 0, button:GetWide(), button:GetTall()) -- create a rectangle that covers the button
end
button.OnMousePressed = function()
button.Colour = Color(0, 200, 0, 255) -- give the variable this green colour, because the Paint function is updated every frame, the button will change to green
end
button.OnMouseReleased = function()
button.Colour = Color(200, 0, 0, 255) -- and when released, the button turns red
end
|