Lançado Adianti Framework 7.6!
Clique aqui para saber mais
Alterando o estilo de componentes dinamicamente Neste exemplo, vamos demonstrar como alterar o estilo de um elemento (TLabel) após a postagem do formulário. Nesta página, vamos criar um formulário simples somente com dois campos e um botão "Salvar" conectado ao método onSave(). Quando o usuário clicar no botão "Salvar", o método onSave() é executado. Então, alteramos o estilo do atributo label Neste atributo, temos um objeto TLabel, ...
PD
Alterando o estilo de componentes dinamicamente  
Fechado
Neste exemplo, vamos demonstrar como alterar o estilo de um elemento (TLabel) após a postagem do formulário. Nesta página, vamos criar um formulário simples somente com dois campos e um botão "Salvar" conectado ao método onSave(). Quando o usuário clicar no botão "Salvar", o método onSave() é executado. Então, alteramos o estilo do atributo label Neste atributo, temos um objeto TLabel, parte do formulário. O estilo é alterado por meio dos métodos: setFontStyle(), que habilita bold, itálico ou sublinhado; e setFontColor() que altera a cor da fonte.

  1. <?php
  2. /**
  3.  * ChangeStyleView report
  4.  *
  5.  * @version    1.0
  6.  * @package    samples
  7.  * @subpackage tutor
  8.  * @author     Pablo Dall'Oglio
  9.  * @copyright  Copyright (c) 2006-2011 Adianti Solutions Ltd. (http://www.adianti.com.br)
  10.  * @license    http://www.adianti.com.br/framework-license
  11.  */
  12. class ChangeStyleView extends TPage
  13. {
  14.     private $form;
  15.     private $label1;
  16.     private $label2;
  17.     
  18.     /**
  19.      * Class constructor
  20.      * Creates the page and the registration form
  21.      */
  22.     function __construct()
  23.     {
  24.         parent::__construct();
  25.         
  26.         // create the form
  27.         $this->form = new TForm;
  28.         
  29.         $table = new TTable;
  30.         $this->form->add($table);
  31.         
  32.         $this->label1 = new TLabel('Object 1:');
  33.         $this->label2 = new TLabel('Object 2:');
  34.         
  35.         // create the form fields
  36.         $field1 = new TEntry('field1');
  37.         $field2 = new TEntry('field2');
  38.         
  39.         // add a row for one field
  40.         $row=$table->addRow();
  41.         $row->addCell($this->label1);
  42.         $cell $row->addCell$field1 );
  43.         
  44.         // add a row for one field
  45.         $row=$table->addRow();
  46.         $row->addCell($this->label2);
  47.         $cell $row->addCell$field2 );
  48.         
  49.         // creates the action button
  50.         $button1=new TButton('action1');
  51.         $button1->setAction(new TAction(array($this'onSave')), 'Save');
  52.         $button1->setImage('ico_save.png');
  53.         
  54.         // define wich are the form fields
  55.         $this->form->setFields(array($field1$field2$button1));
  56.         
  57.         // add a row for the button
  58.         $row=$table->addRow();
  59.         $row->addCell($button1);
  60.         
  61.         // add the form inside the page
  62.         parent::add($this->form);
  63.     }
  64.     /**
  65.      * method onSave()
  66.      * Executed whenever the user clicks at the Save button
  67.      */
  68.     function onSave()
  69.     {
  70.         try
  71.         {
  72.             $data $this->form->getData();
  73.             $this->form->setData($data);
  74.             
  75.             $this->label1->setFontStyle('b');
  76.             $this->label1->setFontColor('red');
  77.         }
  78.         catch (Exception $e// in case of exception
  79.         {
  80.             // shows the exception error message
  81.             new TMessage('error''<b>Error</b> ' $e->getMessage());
  82.         }
  83.     }
  84. }
  85. ?>

Curso completo Meu Negócio Pronto
Use para si, ou transforme em um negócio: Inclui aulas e códigos-fontes
Gestor de conteúdo (SITE) + Loja Virtual (E-Commerce) + Emissor de Notas para infoprodutos


Meu negócio pronto Quero me inscrever agora!

Comentários (0)