• 大小: 14KB
    文件类型: .cs
    金币: 2
    下载: 2 次
    发布日期: 2021-05-14
  • 语言: C#
  • 标签: C#  

资源简介

C#,Winform TabControl重写(添加关闭与添加按钮鼠标移动变色功能),可自定义添加按钮及样式

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using VideoBrowser.Properties;

namespace VideoBrowser.UI
{
    public partial class MenuTabControl : System.Windows.Forms.TabControl
    {
        public MenuTabControl()
        {
            InitializeComponent();
            TabSet();

        }

        private void InitializeComponent()
        {
            this.SuspendLayout();
            this.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.tabMenu_DrawItem);
            this.DrawMode = TabDrawMode.OwnerDrawFixed;
            this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.MainTabControl_MouseDown);
            this.ResumeLayout(false);
        }

        public void AddPage(MouseEventArgs eTabPage page)
        {
            if (e.Button == MouseButtons.Left)
            {
                int x = e.X y = e.Y;
                Rectangle r = this.GetTabRect(0);
                int tx = (int)((r.Width * this.TabCount));
                r.Offset(tx 0);
                r.Width = 30;
                r.Height = 30;
                int longw=((this.TabCount+1) * this.ItemSize.Width + 30);
                if (this.Width < longw)
                {
                    page.Dispose();
                    return;
                }
                bool isAdd = x > r.X && x < r.Right && y > r.Y && y < r.Bottom;
                if (isAdd)
                {
                    this.Controls.Add(page);
                }
                else
                {
                    page.Dispose();
                }
            }
        }

        Color SelectedColor = Color.LightSkyBlue;
        Color MoveColor = Color.White;
        Color FontColor = Color.Black;
        int TextLeft = 10;
        [Browsable(true)]
        [Description(“选项卡标题左边距“) Category(“TextLeft“) DefaultValue(typeof(Int32) “10“)]
        public int titleTextLeft
        {
            get
            {
                return TextLeft;
            }
            set
            {
                this.TextLeft = value;
            }

        }

        [Browsable(true)]
        [Description(“选项卡标题字体颜色“) Category(“titleColor“) DefaultValue(typeof(Color) “Black“)]
        public Color titleFontColor
        {
            get
            {
                return FontColor;
            }
            set
            {
                this.FontColor = value;
            }

        }

        [Browsable(true)]
        [Description(“选项卡标题字体选中颜色“) Category(“titleColor“) DefaultValue(typeof(Color) “LightSkyBlue“)]
        public Color titleSelectedColor
        {
            get
            {
                return SelectedColor;
            }
            set
            {
                this.SelectedColor = valu

评论

共有 条评论