【Winfrom-Panel】Panel隐藏与显示,自动隐藏菜单, Auto-Hide Menu

设计界面:2个button,一个panel

当鼠标移动到btnHome时,显示menuPanel 

当鼠标离开btnHome时,隐藏menuPanel

当btnPin箭头向左时,menuPanel为自动隐藏状态

当btnPin箭头向下时,menuPanel为固定显示状态

From1代码:

namespace Demo
{
    public partial class Form1 : Form
    {
        public int pin = 0;

        public Form1()
        {
            InitializeComponent();
            menuPanel.Visible = false;
        }

        void ChangeIconPin()
        {
            switch (pin)
            {
                case 0:
                    //Changes the pin-icon to display a unpinned frame.
                    this.btnPin.BackgroundImage = Demo.Properties.Resources.left;
                    break;

                case 1:
                    //Changes the pin-icon to display a pinned frame.
                    this.btnPin.BackgroundImage = Demo.Properties.Resources.down;
                    break;
            }
        }

        private void btnHome_MouseHover(object sender, EventArgs e)
        {
            menuPanel.Visible=true;
        }

        private void Form1_MouseEnter(object sender, EventArgs e)
        {
              if (pin == 0)
            {
                menuPanel.Visible = false;
            }
            else
            {
                return;
            }
        }

        private void btnPin_Click(object sender, EventArgs e)
        {
            switch (pin)
            {
                case 0:
                    pin = 1;
                    ChangeIconPin();
                    break;
                case 1:
                    pin = 0;
                    ChangeIconPin();
                    break;
            }
        }
    }
}
原文地址:https://www.cnblogs.com/Sukie-s-home/p/6737596.html