Exemplo n.º 1
0
 // TabControl DrawItem, used to the draw the X on each tab
 private void TabControlClient_DrawItem(object sender, DrawItemEventArgs e)
 {
     //Draw the name of the tab
     e.Graphics.DrawString(TabControlClient.TabPages[e.Index].Text, e.Font, Brushes.Black, e.Bounds.Left + 10, e.Bounds.Top + 7);
     for (int i = 1; i < TabControlClient.TabPages.Count; i++)
     {
         Rectangle tabRect = TabControlClient.GetTabRect(i);
         //Not active tab
         if (i != TabControlClient.SelectedIndex)
         {
             //Rectangle r = TabControlClient.TabPages[i].Text;
             using (Brush brush = new SolidBrush(Color.OrangeRed))
             {
                 e.Graphics.FillRectangle(brush, tabRect.Right - 23, 6, 16, 16);
             }
             using (Pen pen = new Pen(Color.Black, 2))
             {
                 e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
                 e.Graphics.DrawLine(pen, tabRect.Right - 9, 8, tabRect.Right - 21, 20);
                 e.Graphics.DrawLine(pen, tabRect.Right - 9, 20, tabRect.Right - 21, 8);
                 e.Graphics.SmoothingMode = SmoothingMode.Default;
                 pen.Color = Color.Red;
                 pen.Width = 1;
                 e.Graphics.DrawRectangle(pen, tabRect.Right - 23, 6, 16, 16);
                 pen.Dispose();
             }
         }
         //Active tab
         else
         {
             //Rectangle r = TabControlClient.TabPages[i].Text;
             //RectangleF tabXarea = new Rectangle(tabRect.Right - TabControlClient.TabPages[i].Text.Length, tabRect.Top, 9, 7);
             using (Brush brush = new SolidBrush(Color.Silver))
             {
                 e.Graphics.FillRectangle(brush, tabRect.Right - 23, 6, 16, 16);
             }
             using (Pen pen = new Pen(Color.Black, 2))
             {
                 e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
                 e.Graphics.DrawLine(pen, tabRect.Right - 9, 8, tabRect.Right - 21, 20);
                 e.Graphics.DrawLine(pen, tabRect.Right - 9, 20, tabRect.Right - 21, 8);
                 e.Graphics.SmoothingMode = SmoothingMode.Default;
                 pen.Color = Color.Red;
                 pen.Width = 1;
                 //e.Graphics.DrawRectangle(pen, tabXarea.X + tabXarea.Width - 18, 6, 16, 16);
                 e.Graphics.DrawRectangle(pen, tabRect.Right - 23, 6, 16, 16);
                 pen.Dispose();
             }
         }
     }
 }
Exemplo n.º 2
0
        // Click event on TabPage, checks whenever the click was in the X rectangle area
        private void TabControlClient_MouseClick(object sender, MouseEventArgs e)
        {
            for (int i = 1; i < TabControlClient.TabPages.Count; i++)
            {
                Rectangle tabRect = TabControlClient.GetTabRect(i);
                //Getting the position of the "x" mark.

                //Rectangle tabXarea = new Rectangle(tabRect.Right - TabControlClient.TabPages[i].Text.Length, tabRect.Top, 9, 7);
                Rectangle closeXButtonArea = new Rectangle(tabRect.Right - 23, 6, 16, 16);
                //Rectangle closeButton = new Rectangle(tabRect.Right - 13, tabRect.Top + 6, 9, 7);
                if (!closeXButtonArea.Contains(e.Location))
                {
                    continue;
                }
                if (MessageBox.Show(@"Would you like to Close this Tab?", @"Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
                {
                    continue;
                }
                ClientNetworkEngine.PrivateClose(TabControlClient.TabPages[i].Name);
                TabControlClient.TabPages.RemoveAt(i);
                break;
            }
        }