码迷,mamicode.com
首页 > 其他好文 > 详细

可折叠的带过滤功能的分割控件

时间:2018-01-31 22:22:13      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:padding   his   eve   list   bar   pac   draw   size   win   

技术分享图片

 资源部分在QQ群:616945527

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
//CreateByZGJ 1981633
namespace BaseUserControl
{
public partial class UCAlphaCollapseBar : UserControl
    {
        public enum PressButton
        {
            COLLAPSE_BUTTON=1,
            ALL_BUTTON,
            ALPHA_BUTTON
        }
        /// <summary>
        /// 代理事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <param name="pressButton">点击的按钮</param>
        /// <param name="data">按钮附加信息</param>
        public delegate void PressBarButtonHandler(object sender, EventArgs e,PressButton pressButton,String data);
        //添加事件代理
        public event PressBarButtonHandler BarButtonClick;
        public Boolean bCollapse = false;
        private int orgParentWidth = 0;
        public UCAlphaCollapseBar()
        {
            InitializeComponent();
            buttonALL.Click+= new EventHandler(ControlClickEvent);
            buttonCollapse.Click += new EventHandler(ControlClickEvent);
        }
        /// <summary>
        /// 添加按钮
        /// </summary>
        /// <param name="dataList"></param>
        public void AddButton(List<string> dataList,bool bSort=false)
        {
            ClearButtons();
            if (bSort)
            dataList.Sort();
            for (int i = 0; i < dataList.Count; i++)
            {
                Button button = new Button();
                button.Margin = Padding.Empty;
                button.Text = dataList[i];
                button.Height = 30;
                button.FlatStyle = FlatStyle.Flat;
                button.FlatAppearance.BorderSize = 0;
                button.TextAlign = ContentAlignment.MiddleCenter;
                button.Dock = DockStyle.Top;
                panelMain.Controls.Add(button);
                button.BringToFront();
                button.Tag = "alphabutton";
                button.Click += new EventHandler(ControlClickEvent);
            }
        }
        /// <summary>
        /// 重置所有按钮颜色
        /// </summary>
        private void ResetAllButtonsColor()
        {
            buttonALL.ForeColor = Color.Black;
            //不删除前两个按钮
            for (int i = panelMain.Controls.Count - 1; i >= 0; i--)
            {
                panelMain.Controls[i].ForeColor=Color.Black;
            }
        }
        /// <summary>
        /// 清空按钮
        /// </summary>
        public void ClearButtons()
        {
            //不删除前两个按钮
            for (int i = panelMain.Controls.Count-1; i >=0 ; i--)
            {
                panelMain.Controls[i].Dispose();
            }
        }
        protected void ControlClickEvent(object sender, EventArgs e)
        {
            Button button = (Button)sender;
            PressButton pressButton;
            //点了全部按钮
            if (buttonALL==button)
            {
                ResetAllButtonsColor();
                buttonALL.ForeColor = Color.DarkGreen;
                pressButton = PressButton.ALL_BUTTON;
                BarButtonClick(sender, e, pressButton, "");
            }
            else if(buttonCollapse==button)
            {
                if(buttonCollapse.Text=="<<")
                {
                    for (int i = 0; i < this.Parent.Controls.Count; i++)
                    {
                        if(this.Parent.Controls[i]!=this)
                        {
                            this.Parent.Controls[i].Visible = false;
                        }
                    }
                    orgParentWidth = this.Parent.Width;
                    this.Parent.Width = this.Width;
                    buttonCollapse.Text = ">>";
                    bCollapse = true;
                }
                else
                {
                    for (int i = 0; i < this.Parent.Controls.Count; i++)
                    {
                        if (this.Parent.Controls[i] != this)
                        {
                            this.Parent.Controls[i].Visible = true;
                        }
                    }
                    this.Parent.Width = orgParentWidth;
                    buttonCollapse.Text = "<<";
                    bCollapse = false;
                }
                pressButton = PressButton.COLLAPSE_BUTTON;
                BarButtonClick(sender, e, pressButton, bCollapse.ToString());
            }
            else
            {
                if(button.Tag.ToString()== "alphabutton")
                {
                    ResetAllButtonsColor();
                    button.ForeColor = Color.DarkGreen;
                    
                }
                pressButton = PressButton.ALPHA_BUTTON;
                BarButtonClick(sender, e, pressButton, button.Text);
            }
            
        }
    }
}

 

可折叠的带过滤功能的分割控件

标签:padding   his   eve   list   bar   pac   draw   size   win   

原文地址:https://www.cnblogs.com/zhaogaojian/p/8393939.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!