C#仿WINDOWS可摺疊導航欄

C#實現摺疊式  菜單
源代碼:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private Font ft = new Font("黑體",12);
        private static Panel iPanel= new Panel();
        private static PictureBox iPict =new PictureBox();

        private void Form1_Load(object sender, EventArgs e)
        {
            pictureBox1.Image = global::WindowsFormsApplication2.Properties.Resources.朝上按鈕;
            pictureBox1.Size = global::WindowsFormsApplication2.Properties.Resources.朝上按鈕.Size;
            pictureBox2.Image = global::WindowsFormsApplication2.Properties.Resources.朝上按鈕;
            pictureBox2.Size = global::WindowsFormsApplication2.Properties.Resources.朝上按鈕.Size;
            ft = label1.Font;
        }

        private void label1_MouseEnter(object sender, EventArgs e)
        {
            ((Label)sender).ForeColor = Color.Red;//設置控件文字字顏色
            ((Label)sender).Font = new Font(ft, ft.Style | FontStyle.Underline);//設置控件字體
        }

        private void label1_MouseLeave(object sender, EventArgs e)
        {
            ((Label)sender).ForeColor = Color.Black;//設置控件文字顏色
            ((Label)sender).Font = new Font(ft, ft.Style); //設置控件字體
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            int i = Convert.ToInt16(((PictureBox)sender).Tag.ToString());
            switch (i)
            {
                case 1:
                    iPanel = panel2_1;
                    iPict = pictureBox1;
                    break;
                case 2:
                    iPanel = panel2_2;
                    iPict = pictureBox2;
                    break;
            }

            if (Convert.ToInt16(iPanel.Tag.ToString()) == 1)
            {
                iPanel.Tag = 2;
                iPict.Image = Properties.Resources.朝上按鈕;
                iPanel.Visible = true;
            }
            else
            {
                iPanel.Tag = 1;
                iPict.Image = Properties.Resources.朝下按鈕;
                iPanel.Visible = false;
            }
        }
    }
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章