【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;
            }
        }
    }
}

 

posted @ 2017-04-20 11:00  发明创造小能手  阅读(1564)  评论(0编辑  收藏  举报
levels of contents