How to convert Sender to a Form?

Asked

Viewed 67 times

0

In my program, I need the following routine to work:

private void FuncaoTal()
{
  frmSelecao.FormClosing += atualizarEvento;
  SplitContMenu.Panel2.Controls.Clear();
  splitContMenu.Panel2.Controls.Add(frmSelecao);
  frmSelecao.Show();
}
private void atualizarEvento(Object sender, EventArgs e)
{
   if (ContaAtiva.id == 0)
   {
     sender(as Form).FormClosed += carregarLogoVanguarda;
   }
   else
   {
     sender(as Form).FormClosed += acessarMenuMovimentacoes;
   }
}
public void acessarMenuMovimentacoes(object sender, EventArgs e)
    {
        frmMenuMovimentacao frm = new frmMenuMovimentacao();
        frm.AutoScroll = true;
        frm.Dock = DockStyle.Fill;
        frm.TopLevel = false;
        splitContMenu.Panel2.Controls.Clear();
        splitContMenu.Panel2.Controls.Add(frm);
        frm.FormClosed += carregarLogoVanguarda;
        if (ContaAtiva.id > 0)
        {
            frm.Show();
        }
    }
private void carregarLogoVanguarda(object sender, EventArgs e)
    {
        PictureBox picBoxLogo = new PictureBox();
        picBoxLogo.Image = global::InterfaceVisual.Properties.Resources.Logo_Vanguarda;
        picBoxLogo.Dock = DockStyle.Fill;
        picBoxLogo.SizeMode = PictureBoxSizeMode.CenterImage;
        picBoxLogo.BackColor = Color.White;
        splitContMenu.Panel2.Controls.Clear();
        splitContMenu.Panel2.Controls.Add(picBoxLogo);
    }

I’m not getting to make the event update routine work.

My intention is that when the user selects an account on the selection screen, the screen will be closed and in its place another one will be opened. Otherwise, it will carry the home screen again.

P.S.: I am using SplitContainer. The screens are loaded in the panel 2 his.

2 answers

1


You’re using the wrong syntax. Right:

sender as Form

sender(as Form) would be an attempt to call sender as a function, and then an ugly compilation error because the compiler has no idea what to do with as Form, even more use it as parameter.

  • 1

    Just by supplementing your answer, the syntax would be: (Sender as Form). Formclosed += chargeLogoVanguard;

0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.