Skip to content

View

The View class is a base class for all UI controls. It provides properties and methods for managing the appearance, layout, and behavior of the control. Also class View can be used as a container (Panel) for other controls.

Properties:

  • app: App (read-only)
    The app to which the view belongs.
  • parent: View
    Parent of the control. In the case of PageView and DialogView parent is unassigned.
  • children: View[] (read-only)
    List of child controls of the current control.
  • name: string
    Each control can be named (name must be unique). Later on, you can search for a control using its name.
  • align: Align
    The alignment of the control within its parent. See Align enum.
  • left: number | string
    The left position of the control (relative to its parent). Value should be in the form: 25/'10ch'/'25%' (ch - character width. % - percentage of the parent width).
  • top: number | string
    The top position of the control (relative to its parent). Value should be in the form: 25/'10ch'/'25%' (ch - character width. % - percentage of the parent width).
  • width: number | string
    The width of the control (relative to its parent). Value should be in the form: 25/'10ch'/'25%' (ch - character width. % - percentage of the parent width).
  • height: number | string
    The height of the control (relative to its parent). Value should be in the form: 25/'10ch'/'25%' (ch - character width. % - percentage of the parent width).
  • visible: boolean
    Determines whether the control is visible.
  • enabled: boolean
    Determines whether the control is enabled.
  • border: boolean
    Specifies if the control has a border.
  • margins: Margins (read-only)
    The margins around the control. When setting the value, it is possible to also specify a number or a string in the form: 25/'10ch'/'25%' (ch - character width. % - percentage of the parent width).
  • background: string
    The background color name or RGB color code of the control.
    For example: "red’, “blue", "#FF23A0".
  • foreground: string
    The foreground color name of the control. You can use Colors enumeration like Colors.Red. Also it’s possible to specify a RGB pattern like "#FF23A0".
  • font: Font
    The font used for rendering text in the view.
  • cursor: Cursor
    The cursor style used when hovering over the control. You can use some of the cursor enumeration like Cursor.Default, Cursor.Arrow, Cursor.Cross, Cursor.Hand, etc.
  • tabOrder: number
    The tab order of the control for keyboard navigation.
  • disposed: boolean (read-only)
    Indicates whether the underlying control has been destroyed. A View object might exist even after it’s not used any more (garbage collector will free it at some point), but the underlying UI element will be destroyed on app close at the latest.

Methods:

  • show(...buttons?: string[])
    Used for PageView and DIalogView. For any other View implementation it is equivalent to setting visible property to true.
  • buttons: A list of dialog buttons. Used only for DIalogView.
  • Returns the pressed button in DIalogView. Otherwise returns undefined.
  • showModal(...buttons?: string[])
    Used only in DIalogView. Crates a modal dialog that blocks UI until it’s closed.
  • hide()
    Hides the control. Equivalent to setting visible property to false.
  • close(handler?: ()=> boolean)
    Can be used to close PageView or DIalogView (if the handler parameter is omitted). Alternatively, by supplying a handler function, you can listen for the control’s close event which is fired on app closing. If the 'close' event handler returns false, app closing will be prevented. For example: you can use the 'close' event handler to ask the user to save unsaved records/documents.
  • focus()
    Sets focus on control.
  • dispose(handlerOrResult: any | () => any)
    Disposes the underlying UI element of the control. In the case of DIalogView you can pass a value to be returned by the show() method. If a handler method is used, it will be called on control disposal.
  • click(handler?: ()=> boolean)
    Listen control’s click events. Each control in the UI can fire a click event, If a control in its click event handler returns true (meaning event was handled), parent control will not receive the click event. If called without a handler parameter it will simulate the 'click' event.
  • dblClick(handler?: ()=> boolean)
    Listen control’s double-click events. Each control in the UI can fire a double-click event, If a control in its click event handler returns true (meaning event was handled), parent control will not receive the double-click event. If called without a handler parameter it will simulate the 'double-click' event.
  • contextMenu(handler: ()=> Command[]):
    Listen control’s right mouse click events.
  • keyDown(handler: (key: number, shift: boolean, alt: boolean, ctrl: boolean) => boolean)
    Listen control’s key-down events. Each control in the UI can fire a key-down event, If a control in its key-down event handler returns true (meaning event was handled), parent control will not receive the key-down event.
    Example how to catch Ctrl+Enter key press
    this.keyDown((key, shift, alt, ctrl) => {  
      if (!shift && !alt && ctrl && key == 13) {    // Ctrl+Enter   
          // do something ;  
          return true; // handled   
      }  
      else if (!shift && !alt && ctrl && key == 83) { // Ctrl+S   
          // do something ;  
          return true; // handled   
      }  
    });