Greetings.
I've been able to do it here in a way that I think meets what you need.
The events used will be MouseHover and MouseLeave .
I've created a Panel that will serve as a sidebar, this panel will be called pnlMenuLateral .
In the menu panel I added two labels, one to open the submenu Sales (lbl Sales) and the other to open the Subscribers (lblCounts).
When you hover over the sales name, you open the sales menu and pick up any other open menu. The same will happen with the menu entries.
I added 2 Timer components to the project that will help us in visualizing the subMenus. Change the range of these timers to 5.
I'll call Timer Sales and timerCounts .
Change the size of the subMenus panels to Width = 0;
Let's Go To The Codes:
// estas duas variáveis controlarão o tamanho das panels dos subMenus
// no meu caso aqui elas tem um whidth = 68, veja qual o tamanho total do
// seu para que apareçam todos os componentes do subMenu
int tamanhoVendas = 0;
int tamanhoCadastros = 0;
// ao passar o mouse no "lblVendas" é apresentado o submenu de vendas
private void lblVendas_MouseHover(object sender, EventArgs e)
{
pnlCadastros.Size = new Size(pnlCadastros.Width, tamanhoCadastros);
timerVendas.Start();// estamos escondendo o menu de cadastro
}
// parando o timer de vendas e zerando o tamanho da panel de vendas
private void lblVendas_MouseLeave(object sender, EventArgs e)
{
timerVendas.Stop();
tamanhoVendas = 0;
}
// aqui estamos fazendo a verificação para parar ou mostrar o subMenu de Vendas
private void timerVendas_Tick(object sender, EventArgs e)
{
if (tamanhoVendas > 255)
timerVendas.Stop();
else
{
pnlVendas.Size = new Size(pnlVendas.Size.Width, tamanhoVendas);
tamanhoVendas += 5;
}
}
Now let's repeat the same step for the records menu
private void lblCadastro_MouseHover(object sender, EventArgs e)
{
pnlVendas.Size = new Size(pnlVendas.Width, tamanhoVendas);
timerCadastros.Start();
}
private void lblCadastro_MouseLeave(object sender, EventArgs e)
{
timerCadastros.Stop();
tamanhoCadastros = 0;
}
private void timerCadastros_Tick(object sender, EventArgs e)
{
if (tamanhoCadastros > 255)
timerCadastros.Stop();
else
{
pnlCadastros.Size = new Size(pnlCadastros.Size.Width, tamanhoCadastros);
tamanhoCadastros += 5;
}
}
To end, let's make the mouse move from the top of the submenu names
The SubMenus themselves hide again.
I'll do this twice, once for when I hover with the mouse up the panelMenu and another when leaving with the mouse to the side of the main form. See what situation meets you or if in my case both.
private void pnlMenu_MouseHover(object sender, EventArgs e)
{
pnlCadastros.Size = new Size(pnlCadastros.Width, tamanhoCadastros);
pnlVendas.Size = new Size(pnlVendas.Width, tamanhoVendas);
}
private void frmEspandirMenuLateral_MouseHover(object sender, EventArgs e)
{
pnlCadastros.Size = new Size(pnlCadastros.Width, tamanhoCadastros);
pnlVendas.Size = new Size(pnlVendas.Width, tamanhoVendas);
}
That's right, I did the tests here and it worked perfectly.