• Derma DButton help
    6 replies, posted
So im using a Derma menu I have given to an NPC cl_init: [CODE]local function myMenu() local Frame = vgui.Create( "DFrame" ) Frame:SetPos( ScrW() * .292, ScrH() * .390 ) Frame:SetSize( 300, 300 ) Frame:SetTitle( "Ambassador" ) Frame:SetVisible( true ) Frame:SetDraggable( true ) Frame:ShowCloseButton( true ) Frame:MakePopup() end local DButton = vgui.Create( "DButton" ) DButton:SetPos( ScrW() * .292, ScrH() * .390 ) DButton:SetText( "Please click me!" ) DButton:SetSize( 120, 60 ) DButton.DoClick = function() print( "Button was clicked!" ) end[/CODE] The Derma menu opens fine, but the test button appears on the screen even when I dont have the derma menu open. The button works fine, but I need to put it inside the menu, and only open when I open the derma, and close when I close the derma. Please help, thanks!
You have to parent the button to the frame :-) changed: [CODE]local DButton = vgui.Create( "DButton" )[/CODE] to [CODE]local DButton = vgui.Create( "DButton", Frame)[/CODE] [CODE]local function myMenu() local Frame = vgui.Create( "DFrame" ) Frame:SetPos( ScrW() * .292, ScrH() * .390 ) Frame:SetSize( 300, 300 ) Frame:SetTitle( "Ambassador" ) Frame:SetVisible( true ) Frame:SetDraggable( true ) Frame:ShowCloseButton( true ) Frame:MakePopup() local DButton = vgui.Create( "DButton", Frame ) DButton:SetPos( Frame:GetWide()/2 - 60, Frame:GetTall()/2 - 30 ) DButton:SetText( "Please click me!" ) DButton:SetSize( 120, 60 ) DButton.DoClick = function() print( "Button was clicked!" ) end end[/CODE]
A few problems, first, why not just put the button in the mymenu function, since frame is local to the function it wont parent if it isn't, or frame could be made global. Also when parenting the button to the frame it's pos is relevant to the frame, so you can set pos to 0,0 or just use DButton:Center() or whatever and also keep in mind that you can use Frame:GetLong() and Frame:GetWide() to work like ScrW() and SrcH().
Oh yeah i forgot, i was too hasty. Made changes to my post :-)
[QUOTE=jolo309;49559802]You have to parent the button to the frame :-) changed: [CODE]local DButton = vgui.Create( "DButton" )[/CODE] to [CODE]local DButton = vgui.Create( "DButton", Frame)[/CODE] [CODE]local function myMenu() local Frame = vgui.Create( "DFrame" ) Frame:SetPos( ScrW() * .292, ScrH() * .390 ) Frame:SetSize( 300, 300 ) Frame:SetTitle( "Ambassador" ) Frame:SetVisible( true ) Frame:SetDraggable( true ) Frame:ShowCloseButton( true ) Frame:MakePopup() local DButton = vgui.Create( "DButton", Frame ) DButton:SetPos( Frame:GetWide()/2 - 60, Frame:GetTall()/2 - 30 ) DButton:SetText( "Please click me!" ) DButton:SetSize( 120, 60 ) DButton.DoClick = function() print( "Button was clicked!" ) end end[/CODE][/QUOTE] I appreciate the kindness, and help. But it didnt exactly work. [editline]18th January 2016[/editline] [QUOTE=monkeymacman;49559978]A few problems, first, why not just put the button in the mymenu function, since frame is local to the function it wont parent if it isn't, or frame could be made global. Also when parenting the button to the frame it's pos is relevant to the frame, so you can set pos to 0,0 or just use DButton:Center() or whatever and also keep in mind that you can use Frame:GetLong() and Frame:GetWide() to work like ScrW() and SrcH().[/QUOTE] So maybe something like this? [CODE]local function myMenu() local Frame = vgui.Create( "DFrame" ) Frame:SetPos( ScrW() * .292, ScrH() * .390 ) Frame:SetSize( 300, 300 ) Frame:SetTitle( "Ambassador" ) Frame:SetVisible( true ) Frame:SetDraggable( true ) Frame:ShowCloseButton( true ) Frame:MakePopup() local DButton = vgui.Create( "DButton", Frame ) DButton:Center() DButton:SetText( "Please click me!" ) DButton:SetSize( 120, 60 ) DButton.DoClick = function() print( "Button was clicked!" ) end[/CODE]
How so, what does it do? :-)
Worked! Thanks to all!
Sorry, you need to Log In to post a reply to this thread.