Change color of a panel when hovering it.

I want to change the color of my panel when I put the cursor on it, any way to do it ?

[lua]
local sW = ScrW()
local sH = ScrH()
local col = Color(255,0,0,255)
local Example = vgui.Create(“DFrame”)
Example:SetSize(500,500)
Example:SetPos(sW / 2 - 250, sH / 2 - 250) – Perfect Center. Maybe Center()?
Example:SetTitle(“Example”)
Example:ShowCloseButton(true)
Example.OnCursorEntered = function() – What happens when the cursor is on it?
surface.SetColor(col) – WE SET THE COLOR TO RED! HOORAY!!!
surface.DrawRect(0, 0, Example:GetWide(), Example:GetTall()) – Don’t forget this, or it wont work.
end
[/lua]

Should work, untested. Enjoy.

That won’t work, the panel needs to be drawn in it’s paint function.

[editline]04:05PM[/editline]

[lua]local sW = ScrW()
local sH = ScrH()
local In = false
local Example = vgui.Create(“DFrame”)
Example:SetSize(500,500)
Example:SetPos(sW / 2 - 250, sH / 2 - 250)
Example:SetTitle(“Example”)
Example:ShowCloseButton(true)
Example.OnCursorEntered = function()
In = true
end
Example.OnCursorExited = function()
In = false
end
Example.Paint = function()
if In then
surface.SetDrawColor(255,0,0,255)
surface.DrawRect(0, 0, Example:GetWide(), Example:GetTall())
end
end[/lua]

One thing about Averice’s code is I don’t think surface.SetColor is function (gotta get SetDrawColor), but I may be mistaken.

edit Null’s right.
doubleedit Err, Null, you still gotta use SetDrawColor, not SetColor.

Fixed, didn’t notice that.

Ops my mistake.

And yer, never bothered to use OnCursorEntered so thanks for the heads up.

Thanks it’s working !

It is possible to make it on any Derma Control the OnCursor… = function () ?

Also I want to make square button and I want to add property on it to make another button under it, it is possible ? ( Like duplicate button )