Difference between revisions of "Label"

From AutoIt Wiki
Jump to navigation Jump to search
m (Example: Syntax Highlighting & code cleanup)
m (Added Syntax and Parameters sections)
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
A Label is simple, plain piece of text appearing in [[GUI]].
+
A '''label''' is a [[Graphical User Interface|GUI]] control whose purpose is to display often simple and plain text.  A label is often used to display a short, simple description of some aspect of the program's current state or a control's intended purpose among other reasons.
  
 +
The function for creating a label is {{Help File|GuiCtrlCreateLabel}}.  The text of the label can be changed using {{Help File|GuiCtrlSetData}} and read using the {{Help File|GuiCtrlRead}} function.  The foreground can be changed with {{Help File|GuiCtrlSetColor}}.  The background color can be changed with {{Help File|GuiCtrlSetBKColor}}.  The function to change the font face and font size is {{Help File|GUICtrlSetFont}}.
  
== Summary ==
+
== Syntax ==
Label is GUI control, which consists of simple, plain piece of text. The function for creating Label is [[GuiCtrlCreateLabel]]. You can change text using [[GuiCtrlSetData]] and read it using [[GuiCtrlRead]] functions.
 
  
 +
The syntax to create a label is:
 +
<syntaxhighlight lang='autoit'>GUICtrlCreateLabel("text", left, top [, width [, height [, style = -1 [, exStyle = -1 ]]]] )</syntaxhighlight>
 +
 +
==== Parameters ====
 +
 +
{|
 +
|text  || The text of the control.
 +
|-
 +
|left  || The left side of the control. If -1 is used then left will be computed according to GUICoordMode.
 +
|-
 +
|top || The top of the control. If -1 is used then top will be computed according to GUICoordMode.
 +
|-
 +
|width || '''[optional]''' The width of the control (default text autofit in width).
 +
|-
 +
|height || '''[optional]''' The height of the control (default text autofit in height).
 +
|-
 +
|style || '''[optional]''' Defines the style of the control. See GUI Control Styles Appendix.
 +
|-
 +
| || default ( -1) : none.
 +
|-
 +
| || forced styles : $SS_NOTIFY, $SS_LEFT
 +
|-
 +
|exStyle || '''[optional]''' Defines the extended style of the control. See Extended Style Table.
 +
|}
  
 
== Example ==
 
== Example ==
This example demonstrates the creation of a GUI label.
+
 
 +
The following example demonstrates the creation of a label.
 +
 
 
<syntaxhighlight lang="autoit">
 
<syntaxhighlight lang="autoit">
 
  #include <GUIConstantsEx.au3>
 
  #include <GUIConstantsEx.au3>
  
  Opt('MustDeclareVars', 1)
+
  Opt("MustDeclareVars", 1)
  
  Example()
+
  Main()
  
  Func Example()
+
  Func Main()
 
     GUICreate("My GUI") ; will create a dialog box that when displayed is centered
 
     GUICreate("My GUI") ; will create a dialog box that when displayed is centered
  
     GUISetHelp("notepad") ; will run notepad if F1 is typed
+
     GUISetHelp("Notepad.exe") ; will run notepad if F1 is typed
  
     Local Const $iOldOpt = Opt("GUICoordMode", 2)
+
     Opt("GUICoordMode", 2)
  
 
     Local Const $widthCell = 70
 
     Local Const $widthCell = 70
  
 
     GUICtrlCreateLabel("Line 1 Cell 1", 10, 30, $widthCell) ; first cell 70 width
 
     GUICtrlCreateLabel("Line 1 Cell 1", 10, 30, $widthCell) ; first cell 70 width
 +
   
 
     GUICtrlCreateLabel("Line 2 Cell 1", -1, 0)              ; next line
 
     GUICtrlCreateLabel("Line 2 Cell 1", -1, 0)              ; next line
 +
   
 
     GUICtrlCreateLabel("Line 3 Cell 2", 0, 0)              ; next line and next cell
 
     GUICtrlCreateLabel("Line 3 Cell 2", 0, 0)              ; next line and next cell
 +
   
 
     GUICtrlCreateLabel("Line 3 Cell 3", 0, -1)              ; next cell same line
 
     GUICtrlCreateLabel("Line 3 Cell 3", 0, -1)              ; next cell same line
 +
   
 
     GUICtrlCreateLabel("Line 4 Cell 1", -3 * $widthCell, 0) ; next line Cell1
 
     GUICtrlCreateLabel("Line 4 Cell 1", -3 * $widthCell, 0) ; next line Cell1
  
     GUISetState() ; will display an empty dialog box
+
     GUISetState(@SW_SHOWNORMAL) ; will display an empty dialog box
  
 
     ; Run the GUI until the dialog is closed
 
     ; Run the GUI until the dialog is closed
    Local $msg
 
 
 
     Do
 
     Do
        $msg = GUIGetMsg()
+
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    Until $msg = $GUI_EVENT_CLOSE
 
 
 
    Opt("GUICoordMode", $iOldOpt)
 
 
  EndFunc  ;==>Example
 
  EndFunc  ;==>Example
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
[[Category:GUI]]

Latest revision as of 00:29, 3 August 2013

A label is a GUI control whose purpose is to display often simple and plain text. A label is often used to display a short, simple description of some aspect of the program's current state or a control's intended purpose among other reasons.

The function for creating a label is GuiCtrlCreateLabel. The text of the label can be changed using GuiCtrlSetData and read using the GuiCtrlRead function. The foreground can be changed with GuiCtrlSetColor. The background color can be changed with GuiCtrlSetBKColor. The function to change the font face and font size is GUICtrlSetFont.

Syntax

The syntax to create a label is:

GUICtrlCreateLabel("text", left, top [, width [, height [, style = -1 [, exStyle = -1 ]]]] )

Parameters

text The text of the control.
left The left side of the control. If -1 is used then left will be computed according to GUICoordMode.
top The top of the control. If -1 is used then top will be computed according to GUICoordMode.
width [optional] The width of the control (default text autofit in width).
height [optional] The height of the control (default text autofit in height).
style [optional] Defines the style of the control. See GUI Control Styles Appendix.
default ( -1) : none.
forced styles : $SS_NOTIFY, $SS_LEFT
exStyle [optional] Defines the extended style of the control. See Extended Style Table.

Example

The following example demonstrates the creation of a label.

 #include <GUIConstantsEx.au3>

 Opt("MustDeclareVars", 1)

 Main()

 Func Main()
     GUICreate("My GUI") ; will create a dialog box that when displayed is centered

     GUISetHelp("Notepad.exe") ; will run notepad if F1 is typed

     Opt("GUICoordMode", 2)

     Local Const $widthCell = 70

     GUICtrlCreateLabel("Line 1 Cell 1", 10, 30, $widthCell) ; first cell 70 width
     
     GUICtrlCreateLabel("Line 2 Cell 1", -1, 0)              ; next line
     
     GUICtrlCreateLabel("Line 3 Cell 2", 0, 0)               ; next line and next cell
     
     GUICtrlCreateLabel("Line 3 Cell 3", 0, -1)              ; next cell same line
     
     GUICtrlCreateLabel("Line 4 Cell 1", -3 * $widthCell, 0) ; next line Cell1

     GUISetState(@SW_SHOWNORMAL) ; will display an empty dialog box

     ; Run the GUI until the dialog is closed
     Do
     Until GUIGetMsg() = $GUI_EVENT_CLOSE
 EndFunc   ;==>Example