GuiComboBoxIsOpen: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "{{Client function}} __NOTOC__ {{New feature/item|3.0157|1.5.6|14489|This function returns the state of combobox.}} ==Syntax== <syntaxhighlight lang="lua"> bool guiComboBoxIs...")
 
(Modify example)
Line 15: Line 15:


==Example==  
==Example==  
This example show info about combobox after click on screen.
This example opens/closes the combobox after clicking the button. Checking if combobox is opened and change button text.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
local comboBox = guiCreateComboBox(0.30,0.45,0.30,0.20,'Test',true) -- create the gui combo-box
local comboBox = guiCreateComboBox(0.30,0.45,0.30,0.20,'Test',true) -- create the gui combo-box
local openButton = guiCreateButton(0.35,0.31,0.15,0.15,'Show numbers',true) -- create the button


for i = 1,20 do
for i = 1,20 do
Line 23: Line 24:
end
end


addEventHandler('onClientClick',root,function(b,s)
addEventHandler('onClientGUIClick',openButton,function()
if b == 'left' and state == 'down' then
if not guiComboBoxIsOpen(comboBox) then
if guiGetVisible(comboBox) then
guiComboBoxSetOpen(comboBox, true) -- open the combobox
local state = guiComboBoxIsOpen(comboBox) -- get state of the combobox
guiSetText(source, 'Hide numbers')
outputChatBox('Combobox is '..(state and 'open' or 'close')) -- show info about combobox
else
end
guiComboBoxSetOpen(comboBox, false) -- close the combobox
guiSetText(source, 'Show numbers')
end
end
end)
end)

Revision as of 17:09, 23 September 2018

This function returns the state of combobox.

Syntax

bool guiComboBoxIsOpen( element comboBox )

Required Arguments

  • comboBox: The combo box to get the state.

Returns

Returns true if combobox is opened, false if combobox is closed, nil otherwise.

Example

This example opens/closes the combobox after clicking the button. Checking if combobox is opened and change button text.

local comboBox = guiCreateComboBox(0.30,0.45,0.30,0.20,'Test',true) -- create the gui combo-box
local openButton = guiCreateButton(0.35,0.31,0.15,0.15,'Show numbers',true) -- create the button

for i = 1,20 do
	guiComboBoxAddItem(comboBox, tostring(i)) -- add items
end

addEventHandler('onClientGUIClick',openButton,function()
	if not guiComboBoxIsOpen(comboBox) then
		guiComboBoxSetOpen(comboBox, true) -- open the combobox
		guiSetText(source, 'Hide numbers')
	else
		guiComboBoxSetOpen(comboBox, false) -- close the combobox
		guiSetText(source, 'Show numbers')
	end
end)

See Also

General functions

Browsers

Buttons

Checkboxes

Comboboxes

Edit Boxes

Gridlists

Memos

Progressbars

Radio Buttons

Scrollbars

Scrollpanes

Static Images

Tab Panels

Tabs

Text Labels

Windows

Input

GUI