SetZPos

I am trying to set a text box just below my derma frame but cannot figure out this zpo thing, can anyone offer some tips?

DFrame
[lua]
local MenuFrame = vgui.Create( “DFrame” )
MenuFrame:SetSize( 500, 300 )
MenuFrame:Center()
MenuFrame:SetTitle( "Welcome " … LocalPlayer():Nick() … “!” )
MenuFrame:SetVisible( true )
MenuFrame:SetDraggable( false )
MenuFrame:ShowCloseButton( true )
MenuFrame:MakePopup()

MainPropertySheet = vgui.Create( "DPropertySheet" )
MainPropertySheet:SetParent( MenuFrame )
MainPropertySheet:SetPos( 0, 23 )
MainPropertySheet:SetSize( 500, 277 )

[/lua]

TextBox
[lua]
local ChatBox = vgui.Create( “DTextEntry” )
ChatBox:SetParent( MenuFrame )
ChatBox:SetZPos( 200 )
ChatBox:SetSize( 1, 0 )
ChatBox.OnMousePressed = function ()
ChatBox:SetText( “” )
end
ChatBox.OnEnter = function ()
RunConsoleCommand( “say”, MenuChatBox:GetValue() )
ChatBox:SetText( “” )
end
[/lua]

There is no absolute scale for ZPos, it just depends on the numbers you start with. A greater ZPos will mean it will draw above, so you could do

[lua]MenuFrame:SetZPos( 2 )
ChatBox:SetZPos( 1 )[/lua]

Doesn’t seem to work, does it matter where I put the code, such as right under the definition of the element?

Weird. Well, in that case, you have two options:

  1. Use **[Panel.MoveToFront

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Panel.MoveToFront)**

  1. Make the frame after the chatbox - similar to CSS, elements created further down in the code will show up before previously created elements.

Hmm can’t seem to get it to work, it would work by creating the textbox first but I am not sure how I would make the textbox close when I hit the x on the dframe.

Here’s how you hook into a DFrame’s close:

[lua]
frame.btnClose.DoClick = function()
– Do stuff
frame:Close()
end[/lua]

Thanks, got it working.