//TabControl DrawItem, used to the draw the X on each tab private void TabControlServer_DrawItem(object sender, DrawItemEventArgs e) { //Draw the name of the tab e.Graphics.DrawString(TabControlServer.TabPages[e.Index].Text, e.Font, Brushes.Black, e.Bounds.Left + 10, e.Bounds.Top + 7); for (int i = 2; i < TabControlServer.TabPages.Count; i++) { Rectangle tabRect = TabControlServer.GetTabRect(i); //Not active tab if (i != TabControlServer.SelectedIndex) { //Rectangle r = TabControlServer.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 = TabControlServer.TabPages[i].Text; //RectangleF tabXarea = new Rectangle(tabRect.Right - TabControlServer.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(); } } } }
// Client Name Changed private void ClientNameChanged(string clientName, string newClientName) { // Change the ListViewItem.name in ListViewClients Invoke(new Action(delegate { foreach (ClientMessagesPosition clientMessagesPosition in _ClientMessagesesList) { if (clientMessagesPosition.ClientName == clientName) { clientMessagesPosition.ClientName = newClientName; } } for (int i = 0; i < ListViewClients.Items.Count; i++) { if (ListViewClients.Items[i].Name != clientName) { continue; } ListViewClients.Items[i].Text = newClientName; ListViewClients.Items[i].Name = newClientName; break; } foreach (TabPagePrivateChatServer tabPage in TabControlServer.TabPages.OfType <TabPagePrivateChatServer>()) { if (tabPage.ClientName == clientName) { tabPage.ClientName = newClientName; tabPage.Text = newClientName + @" - " + tabPage.ClientNamePrivate; TabControlServer.Invalidate(); } if (tabPage.ClientNamePrivate == clientName) { tabPage.ClientNamePrivate = newClientName; tabPage.Text = tabPage.ClientName + @" - " + newClientName; TabControlServer.Invalidate(); } } TabFormat.ItemEvenSize(TabControlServer); // The inner server messages board RichTextServerConn.SelectionStart = _CursorPositionConn; RichTextServerConn.SelectionColor = Color.Black; RichTextServerConn.SelectionBackColor = Color.CornflowerBlue; RichTextServerConn.SelectedText += @"<<< " + clientName + @" have changed his name to " + newClientName + " " + Time.NowTimeDate() + @" >>>" + Environment.NewLine; _CursorPositionConn = RichTextServerConn.SelectionStart; })); if (FrmServerImagesChangeNameEvent != null) { FrmServerImagesChangeNameEvent.Invoke(clientName, newClientName); } }
//Click event on TabPage, checks whenever the click was in the X rectangle area private void TabControlServert_MouseClick(object sender, MouseEventArgs e) { for (int i = 2; i < TabControlServer.TabPages.Count; i++) { Rectangle tabRect = TabControlServer.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)) { if (MessageBox.Show(@"Would you like to Close this Tab?", @"Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { TabControlServer.TabPages.RemoveAt(i); break; } } } }