vgui.Register

From GMod Wiki

Jump to: navigation, search
Function
Syntax vgui.Register( String classname, Table control[, String base] )
Where is this used?
Description:
Registers a new type of control in the VGUI system that can be used. The first argument specifies the name of the control as you would use it with vgui.Create, the second argument is the name of the table that you have stored your data in, and the third ( optional ) argument is what you want to derive this control from.
Returns: nil
Part of Library: vgui
Realm: NewerClient.png
BBCode Link: [b][url=http://wiki.garrysmod.com/?title=Vgui.Register]Vgui.Register [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]



Examples

DescriptionCreate a new type of panel and register it.
Used onNewerClient.png
Code
 
 
-- First, we define a table to store our control in
local PANEL={}
 
-- This is called when the control is created
-- via vgui.Create
function PANEL:Init()
end
 
-- This function is called whenever we need to paint the control
-- ( This is where we define what it looks like. )
function PANEL:Paint()
  -- This draws a round black box as the background for this control
  draw.RoundedBox(6,0,0,self:GetWide(),self:GetTall(),Color(0,0,0,255));
 
  return true; -- Since we are deriving this from another class, we don't want the renderer to call the OnPaint() function of the class that we derived this from.
end
 
-- This function is called whenever this control is pressed
function PANEL:OnMousePressed()
  Msg( "Hello, world!\n" );
end
 
-- Register the new control so that we can use it by doing vgui.Create("panel_example");
vgui.Register( "panel_example", PANEL );
 
OutputN/A


Additional Notes

See Also

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox