// 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(); } } } }
// Name change private void NameChange(string clientName, string clientNameNew, Color color) { Invoke(new Action((delegate { int index = ListBoxClientList.FindString(clientName); ListBoxClientList.Items[index] = clientNameNew; foreach (ClientChatHistory clientColor in _ClientChatHistoryList.Where(ClientChatHistory => ClientChatHistory.Name == clientName)) { clientColor.Name = clientNameNew; } RichTextClientPub.SelectionStart = _CursorPosition; RichTextClientPub.SelectionColor = Color.Black; RichTextClientPub.SelectionBackColor = Color.CornflowerBlue; RichTextClientPub.SelectedText = Time.NowTime() + " " + @"<<< " + clientName + @" have changed nickname to " + clientNameNew + @" >>>" + Environment.NewLine; _CursorPosition = RichTextClientPub.SelectionStart; if (Client.Name == clientNameNew) { Text = @"Chat: " + clientNameNew; } if (TabPagePrivateChatReceiveClientEvent != null) { TabPagePrivateChatReceiveClientEvent.Invoke(clientName, null, clientNameNew, TabPagePrivateChatClient.TabCommand.NameChange); } foreach (TabPage tabPage in TabControlClient.TabPages.Cast <TabPage>().Where(tabPage => tabPage.Name == clientName)) { tabPage.Name = clientNameNew; tabPage.Text = clientNameNew; TabControlClient.Invalidate(); } TabFormat.ItemEvenSize(TabControlClient); }))); Invoke(new Action((delegate { _FrmClientImages.Text = clientNameNew + @" Received Images"; }))); if (FrmClientImagesChangeNameEvent != null) { FrmClientImagesChangeNameEvent.Invoke(clientName, clientNameNew); } ColorChanged(clientName, color); }
// 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; } }