Dúvida label C#

3 respostas
Y
Olá pessoal, estou aprendendo c#, e gostaria de sabe se é possível e como eu mostro uma informação atualizada em um label, ex. uma página principal me mostra informações gerais, na label aparece a lotação naquele momento, mas se eu troco a lotação no label ela precisa atualizar. Aqui eu consigo chamar ela, só não consigo atualizar a mesma com o programa em execução.
public void ApresentaLotacao()
        {
            tssLotacao.Text = "Lotação :" + FormHelper.Lotacao.ToString();
}
Já tentei fazer isso através do selecionar lotação.
Form principal;                

public void ApresentaLotacao()
        {
            tssLotacao.Text = "Lotação :" + FormHelper.Lotacao.ToString();

        }

        public void Atualiza(string strLotacao)
        {
            tssLotacao.Text = "Lotação :" + FormHelper.Lotacao.ToString();
            Application.DoEvents();
        }

Form Seleciona Lotação;

  frmPrincipal frmPrincipal = new frmPrincipal();
  frmPrincipal.Atualiza(FormHelper.Lotacao);

Se alguém conseguir ajudar agradeço.

3 Respostas

E

Application.DoEvents? Isso parece código VB 6 :slight_smile:

Y

Já tentei isto também mas tá dando erro no InvokeRequired.

private delegate void UpdateStatusDelegate(string status);
        private void UpdateStatus(string status)
        {
            if (this.tssLotacao.InvokeRequired)
            {
                this.Invoke(new UpdateStatusDelegate(this.UpdateStatus), new object[] { status });
                return;
            }

            this.tssLotacao.Text = status;
        }

E este.

delegate void ShowLabelDelegate(string text);

        public void ShowLabel(string text)
        {
            if (tssLotacao.InvokeRequired == false)
            {
                tssLotacao.Text = text;
            }
            else
            {
                ShowLabelDelegate showLabel = new ShowLabelDelegate(ShowLabel);
                this.Invoke(showLabel, new object[] { text });
            }
        }
Y

entanglement:
Application.DoEvents? Isso parece código C#

Sim é c#.

Criado 13 de junho de 2012
Ultima resposta 13 de jun. de 2012
Respostas 3
Participantes 2