Hello ,
I want to create a lot of panel for 1 menu associate with but i don't no how i can create a lot of DPanel with a loop
thanks for you helps and enjoy Day
PS: sorry for my mistake i'm french
id say create a function and loop over that or create a table with panel info and loop that,
i imagine that something like one of these is what you're after...
-- function approach
local function makepanel( parent , number )
panel = vgui.Create( "DPanel" , parent )
panel:SetTall( 40 )
panel:Dock( TOP )
function panel:Paint()
surface.DrawText( i )
end
end
local frame = vgui.Create( "DFrame" )
--frame stuff
for i=1,10 do
makepanel( frame , i )
end
-- table approach
panels = {
{ name = "1" , height = 40 },
{ name = "two" , height = 60 },
{ name = "tra" , height = 40 }
}
local frame = vgui.Create( "DFrame" )
-- frame stuff
for k , v in pairs( panels ) do
panel = vgui.Create( "DPanel" , frame )
panel:SetTall( v.height )
panel:Dock( TOP )
function panel:Paint()
surface.DrawText( v.name )
end
end
Thanks for you answers, your 2nd solution works, i wanna have a space between 2 panel how i can do that ?
Sorry, you need to Log In to post a reply to this thread.