How does one draw a custom DButton?

Hi!
I saw a tutorial somewhere on how to draw a custom DButton but i cant find the damn thing. Does anyone know how to draw a simple button in Derma with surface or something?
I have tried:
[lua]
conbutton = vgui.Create(“DButton”, newb)
conbutton:SetPos(50, ScrH()- 200)
conbutton:SetSize(300,80)
conbutton:SetValue(“conbutton”)
conbutton.Paint = function()
surface.SetDrawColor(200,200,200,255)
surface.DrawRect(500,ScrH() - 200, 300, 80)
end
[/lua]
to no avail

The coordinates in the Paint function are relative to the buttons’ location. You cannot draw outside of the button’s “Size” area, so the coordinates you gave it are invalid. Do surface.DrawRect(0, 0, 300, 80)

You can also make the button invisible with “SetPaintedManually(true)” if you wanted to paint the button somewhere else.

[lua]
btn.Paint = function( s, w, h ) // s is the button itself, w is width, h is height.
draw.RoundedBox( 0, 0, 0, w, h, Color( 255, 255, 0 ) )
end
[/lua]

This will make a plain yellow button for example.
You can also use surface library as you did, remember that you need to position the shapes or w/e you’re drawing relatively to the button( that’s btw why your code didn’t work as you wanted, because the rectangle is starting beyond the button’s edge )

Tried this:
[lua]
conbutton = vgui.Create(“DButton”, newb)
conbutton:SetPos(50, ScrH()- 200)
conbutton:SetSize(300,80)
conbutton:SetPaintedManually(true)
conbutton.Paint = function(s,w,h) – I tried the w,h vars too
surface.SetDrawColor(200,200,200,255)
surface.DrawRect(0,0, 300, 80)
end
[/lua]
Still no ;c

Try this, if it doesn’t work try the second one.
[lua]
conbutton = vgui.Create(“DButton”, newb)
conbutton:SetPos(50, ScrH()- 200)
conbutton:SetSize(300,80)
conbutton.Paint = function(w,h)
surface.SetDrawColor(200,200,200,255)
surface.DrawRect(0,0, w, h)
end
[/lua]
Second
[lua]
conbutton = vgui.Create(“DButton”, newb)
conbutton:SetPos(50, ScrH()- 200)
conbutton:SetSize(300,80)
conbutton.Paint = function(w,h)
draw.RoundedBox(0,0,0,w,h,Color(255,50,50,255))
end
[/lua]

maybe you should try the code that was actually posted:

[lua] btn.Paint = function( s, w, h ) // s is the button itself, w is width, h is height.
draw.RoundedBox( 0, 0, 0, w, h, Color( 255, 255, 0 ) )
end[/lua]

I did try that code still to no avail.

you at least renamed the variable from btn to conbutton… Right? You need to be more descriptive in what the issues are.

I definitely renamed the code. Il have another go later and tell you what the result yields.

[editline]31st December 2013[/editline]

Works now aslong as I dont use SetPaintedManually(true)… Any way to make it work with SetPaintedManually?

Got it to work in the end by +1ing the position so I could have the curves on the button. (thats why I wanted SetPaintedManually to work) Thanks!

why do you need to SetPaintedManually(true), what are you doing…

I needed it so I could make a button with rounded edges. If I dont use SetPaintedManually the button would still be visible after painting.

um what

[lua]
local btn = vgui.Create(“DButton”)
btn.Paint = function(_, w, h)
draw.RoundedBox(16, 0, 0, w, h, Color(255, 255, 255, 255))
end
[/lua]

this draws a rounded button, I don’t understand why you’re overcomplicating all this.

As Matt said, when you use .Paint it doesn’t just draw a box ontop. It changes the box into the button. All you need to do is use draw.RoundedBox to make a rounded button.