Derma Button Paint Help

Ok so, whenever I painted my derma button to be green. But I also have a command set with it so. When I open the panel the button shows up the default silver color. And when I click on it, it shows up green. I want it to show up green as soon as I open the panel… Anyone know how to fix this?

Thanks!

Show us the code. We can’t really help you otherwise.

Show code. Make sure you’re overwriting the buttons default paint function.


net.Receive( 'OpenIt', function()
		local base = vgui.Create( 'DFrame' )
			base:SetSize( 600, 300 )
			base:Center()
			base:ShowCloseButton( true )
			base:MakePopup()
			base:SetDraggable( false )
			base:SetTitle( 'Title' )
			function base:Paint( w, h )
				draw.RoundedBox( 0, 0, 0, w, h, Color( 255,0, 0 ) )
				surface.SetDrawColor( 0, 0, 0 )
				surface.DrawOutlinedRect( 1, 1, w-2, h-2 )
			end
		local button = vgui.Create( 'DButton' )
			button:SetParent( base )
			button:SetSize( 150, 100 )
			button:SetPos( 3, 26 )
			button:SetText( 'Button' )
			button.DoClick = function()
			function button:Paint( w, h )
				draw.RoundedBox( 0, 0, 0, w, h, Color( 33, 255, 0 ) )
			end
			for k, ply in pairs( player.GetAll() ) do
					ply:ChatPrint( "Message!" )
				end
		end
end )

Move the paint function outside of the DoClick function

I’m not sure what you mean by that… Could you maybe put it in code form by just copying mine?

No, you’ll learn best by doing it yourself. Take the button:Paint() function, and move it outside of the DoClick function. Like under it

Still, it does not work.



        local base = vgui.Create( 'DFrame' )
            base:SetSize( 600, 300 )
            base:Center()
            base:ShowCloseButton( true )
            base:MakePopup()
            base:SetDraggable( false )
            base:SetTitle( 'Title' )
            base.Paint = function()
                draw.RoundedBox(4, 0, 0, base:GetWide(), base:GetTall(), Color(255, 0, 0, 255))
            end
        local button = vgui.Create( 'DButton', base )
            button:SetSize( 150, 100 )
            button:SetPos( 3, 26 )
            button:SetText( 'Button' )
            button.DoClick = function() end
            button.Paint = function()
                draw.RoundedBox(0, 0, 0, button:GetWide(), button:GetTall(), Color(33, 255, 0, 255))
            end


I’m sorry, your code was atrocious, I fixed a little bit.

Sorry. Just started learning today but thanks :stuck_out_tongue:

[added]1410830210[/added]

so nobody knows?