Greetings.
I managed to do it here in a way that I think suits what you need.
The events used will be the Mousehover and the Mouseleave.
I created a Panel which will serve as a lateral background, this panel will be called pnlMenuLateral.
Inside the menu panel I added two Abels, one to open the submenu Sales(lblVendas) and the other to open the submenu Cadastrals(lblCadastros).
When hovering over the sales name opens the sales menu and collects any other open menu. The same will happen with the registration menu.
I added to the project 2 components of the type Timer that will assist us in visualizing the submenus. Change the range of these timers to 5.
I’ll call it timerVendas and timerCasters.
Change the size of 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 registration 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 Finish we will make that when leaving with the mouse of the names of the submenu
The Submenus themselves hide again.
I will do this twice, once for when leave with the mouse up the panelMenu and another when leaving with the mouse to the side of the main form. See what situation suits you or if equal 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);
}
It’s there, I did the tests here and it worked perfectly.
Hello @user welcome to Stackoverflow, please edit your question and add some code snippets so you can find the problem
– Lucas Duete
Why not use the "menuStrip" component? It already has this function embedded to expand menus.
– Agnaldo