Multiple items in DPropertySheet

From GMod Wiki

Jump to: navigation, search
Lua: Multiple items in DPropertySheet
Page white text.png Description:Shows people how to put more stuff in a single tab
link=User:Brian Nevec Original Author:Brian Nevec
Calendar.png Created:30th April, 2009

So, you have made a very epic menu that has a tab control, but you don't have even the slightest idea on how to add multiple items to a tab? Well then, you have come to the right place. Before I start, I want to say that it's actually very simple.

Here is the code we will start with. Basically, we create a tab control( DPropertySheet ) and two labels.

 
local sheet = vgui.Create( "DPropertySheet" );
sheet:SetSize( 300, 300 );
 
local item1 = vgui.Create( "DLabel" );
item:SetText( "Label 1" );
item:SizeToContents( );
 
local item2 = vgui.Create( "DLabel" );
item2:SetText( "Label 2" );
item2:SizeToContents( );
 

Now what we want to do is add the two labels to the same tab. How on Earth can be do that? Well, here's the simple part. We use a DPanel control! The new panel will act as a "base" to put our labels in.

 
local panel = vgui.Create( "DPanel" );
sheet:AddSheet( "Out labels", panel, nil, false, false, "Two labels" );
 

Now we have a blank tab and we also have a base for our controls.

 
local sheet = vgui.Create( "DPropertySheet" );
sheet:SetSize( 300, 300 );
 
local panel = vgui.Create( "DPanel" );
 
local item1 = vgui.Create( "DLabel", panel );
item:SetText( "Label 1" );
item:SizeToContents( );
 
local item2 = vgui.Create( "DLabel", panel );
item2:SetText( "Label 2" );
item2:SizeToContents( );
 
sheet:AddSheet( "Out labels", panel, nil, false, false, "Two labels" );
 

Here is the full code. You'd want to do any positioning and sizing after the AddSheet line, because the AddSheet method resizes the panel to fit the tab.

Now was that so hard to figure out for yourself?

Good day!

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox