C#自定义带关闭按钮的TabControl实例

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/flyking2/article/details/78943101

网上有很多关于TabCcotrol绘 制关闭按钮的代码,这里是修改以后的支持image的显示的实例

效果图如下:

源代码下载地址:http://download.csdn.net/download/flyking2/10182197



部分代码如下:

如何判断鼠标点击关闭按钮

    protected override void OnMouseDown(MouseEventArgs e)
        {  if (showclose_button == true)
            {
                Point MousePOS = this.PointToClient(Control.MousePosition); //鼠标当前位置
                rectClose = GetCloseRect(this.GetTabRect(this.SelectedIndex));
                above = rectClose.Contains(MousePOS);
                if (above)
                    this.TabPages.Remove(this.SelectedTab);
            }
        }

     /// <summary>
        /// 获得绘制关闭按钮的区域
        /// </summary>
        /// <param name="rect">Tab标签区域</param>
        /// <returns></returns>
        private Rectangle GetCloseRect(Rectangle rect)
        {
           Rectangle closerect = new Rectangle(rect.X+rect.Width - SystemInformation.SmallIconSize.Width, rect.Y+5, SystemInformation.SmallIconSize.Width*3/4, SystemInformation.SmallIconSize.Height*3/4);
            return closerect;
        }


猜你喜欢

转载自blog.csdn.net/flyking2/article/details/78943101