コード例 #1
0
 /// <summary>
 /// 此成员重写 <see cref="M:System.Windows.Forms.Control.WndProc(System.Windows.Forms.Message@)" />。
 /// </summary>
 /// <param name="m">一个 Windows 消息对象。</param>
 protected override void WndProc(ref Message m)
 {
     base.WndProc(ref m);
     if (m.Msg == 0x0201) // WM_LBUTTONDOWN
     {
         if (!DesignMode)
         {
             if (IsShowCloseBtn)
             {
                 var mouseLocation = this.PointToClient(Control.MousePosition);
                 int index         = GetMouseDownTabHead(mouseLocation);
                 if (index >= 0)
                 {
                     if (UncloseTabIndexs != null)
                     {
                         if (UncloseTabIndexs.ToList().Contains(index))
                         {
                             return;
                         }
                     }
                     Rectangle rect      = this.GetTabRect(index);
                     var       closeRect = new Rectangle(rect.Right - 15, rect.Top + 5, 10, 10);
                     if (closeRect.Contains(mouseLocation))
                     {
                         this.TabPages.RemoveAt(index);
                         return;
                     }
                 }
             }
         }
     }
 }
コード例 #2
0
        /// <summary>
        /// Paints the tab.
        /// </summary>
        /// <param name="e">The <see cref="System.Windows.Forms.PaintEventArgs" /> instance containing the event data.</param>
        /// <param name="index">The index.</param>
        private void PaintTab(System.Windows.Forms.PaintEventArgs e, int index)
        {
            GraphicsPath path = this.GetTabPath(index);

            this.PaintTabBackground(e.Graphics, index, path);
            this.PaintTabBorder(e.Graphics, index, path);
            this.PaintTabText(e.Graphics, index);
            this.PaintTabImage(e.Graphics, index);
            if (IsShowCloseBtn)
            {
                if (UncloseTabIndexs != null)
                {
                    if (UncloseTabIndexs.ToList().Contains(index))
                    {
                        return;
                    }
                }
                Rectangle rect = this.GetTabRect(index);
                e.Graphics.DrawLine(new Pen(closeBtnColor, 1F), new Point(rect.Right - 15, rect.Top + 5), new Point(rect.Right - 5, rect.Top + 15));
                e.Graphics.DrawLine(new Pen(closeBtnColor, 1F), new Point(rect.Right - 5, rect.Top + 5), new Point(rect.Right - 15, rect.Top + 15));
            }
        }