Shiny Language Reference
Language Reference > User Interface
setcontrolname
bool setcontrolname(int ID, string Name);
Associates a friendly name with the specified control
When creating controls at runtime (for example by using createbutton or createlistbox), the actual control ID of the new control is returned to the plugin code making it easy to keep track of what control has what ID. However some developers may find it easier to refer to their controls by name. This is especially true when a plugin uses a mixture of Panel Designer layouts (which must be referred to by name) and dynamically created controls.
The SETCONTROLNAME statement allows a developer to associate a unique "friendly name" with a control ID. The developer can subsequently refer to the control using the idfromname statement and the specified name.
Parameters
ID
The ID of the control to set the handler for
Name
The friendly name to associate with the control
Return Value
True if the assignment succeeded (if the control ID was valid), otherwise False.
Example Code
function Init()
{
// Create a "dynamic" button at runtime in the normal way
int ExplorerButtonID = createbutton(1, 10, 10, 50, 20);
// Associate the friendly name "ExpButton" with the control ID
setcontrolname(ExplorerButtonID, "ExpButton"):
// Use the friendly name to set the handler, instead of the control ID
sethandler(idfromname("ExpButton"), "ExplorerHandler");
}