How to convert Sender to a Form?

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 able to make the routine update event work.

It is my intention that when the user selects an account in the selection screen, the screen is closed and in its place another one is opened. Otherwise, it loads the home screen again.

Qs: I'm using SplitContainer . The screens are loaded in panel 2 of it.

    
asked by anonymous 31.01.2014 / 14:52

2 answers

1

You are using the wrong syntax. The right thing is:

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 a parameter.

    
31.01.2014 / 15:02
0

Your code has a box / unboxing issue.

See: link

if (ContaAtiva.id == 0)
{
  (Form)sender.FormClosed += carregarLogoVanguarda;
}
else
{
  (Form)sender.FormClosed += acessarMenuMovimentacoes;
}
    
31.01.2014 / 15:02