Press F1 again to close derma frame

I open my menu with F1, but it won’t close if i press F1 again, and i need to hit the close button, how do i make so it closes when i press f1 again ?

here is my code:


// Start of Main Frame
MainMenuFrame = vgui.Create( "DFrame" )
MainMenuFrame:SetSize( 1000, 600 )
MainMenuFrame:SetTitle("Comingsoon Menu "..Version )
MainMenuFrame:Center( true )
MainMenuFrame:SetVisible( true )
MainMenuFrame:SetDraggable( false )
MainMenuFrame:MakePopup()
MainMenuFrame.Paint = function()
		draw.RoundedBox( 8, 0, 0, MainMenuFrame:GetWide(), MainMenuFrame:GetTall(), Color( 0, 0, 0, 180) )
		end

// End of Main Frame

Try something like this, it’s efficient too because you don’t recreate the panel everytime you open it.



local myframe
local function CreateFrame()
	/*create frame here*/
	myframe = vgui.Create("DFrame")
		myfr...
		myframe:SetDeleteOnClose(false) // Required, is otherwise removed when we do :Close, or close it with X button
end

concommand.Add("toggleframe", function()
	if not myframe then // If it doesn't exist yet
		CreateFrame()
		return
	end
	
	if myframe:IsVisible() then
		myframe:Close()
	else
		myframe:SetVisible(true)
	end
end)


This don’t work, and its a complicated way to do that… or i am just dumb.

It’s not complicated, toggleframe should be bound to the F1 key if you haven’t already. Give us the code you got.


function GM:ShowHelp( ply ) 
ply:ConCommand("vbtdm_old_menu ") 
end

EDITED:
Nevermind

I can’t from work but why don’t you look at the pointshop client side code. I know with it you can open and close the menu with f3.

beacouse i don’t know where to find it, tried google.

Show us the clientside code too.

I am learning lua, trying to learn, can you explain a bit more what file should i show you?

Well, I assumed you adapted your code into my code I gave you, could you show me that?

Ehh, i don’t need this anymore, just made a huge button with function:

TestingPanel:Close() and it works