protected sealed override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; TabPageCollection tabPages = base.TabPages; int selectedIndex = base.SelectedIndex; int tabCount = base.TabCount; if (tabCount > 0) { // Draw the background behind the tabs Rectangle tabChannel = base.GetTabRect(0); tabChannel.X = 0; tabChannel.Width = base.Width; g.FillRectangle(SystemBrushes.Control, tabChannel); // Draw each tab InlineTabRenameTextBox renamingTextBox = myRenamingTextBox; TabPage renamingTabPage = (renamingTextBox != null) ? renamingTextBox.RenamingTabPage : null; for (int i = 0; i < tabCount; i++) { DrawTab(g, base.GetTabRect(i), tabPages[i], i == selectedIndex, renamingTabPage); } } base.OnPaint(e); }
private void DrawTab(Graphics g, Rectangle bounds, TabPage tabPage, bool selected, TabPage renamingTabPage) { const int diagramImagePadding = 2; bounds.Inflate(-TabOutsideBorderLength, -TabOutsideBorderLength); // Draw the background (if selected) and border if (selected) { g.FillRectangle(SystemBrushes.Window, bounds); g.DrawRectangle(SystemPens.WindowFrame, bounds); } else { g.DrawRectangle(SystemPens.ControlDark, bounds); } bounds.Inflate(-TabInsideBorderLength, -TabInsideBorderLength); // Draw the image, if any ImageList imageList = base.ImageList; if (imageList != null) { int imageIndex = imageList.Images.IndexOfKey(tabPage.ImageKey); if (imageIndex >= 0) { int imageY = bounds.Y + ((bounds.Height - DiagramImageHeight) / 2); imageList.Draw(g, bounds.X, imageY, imageIndex); bounds.Width -= DiagramImageWidth + diagramImagePadding; bounds.X += DiagramImageWidth + diagramImagePadding; } } // Draw the text box for renaming or the tab name if (tabPage == renamingTabPage) { InlineTabRenameTextBox renamingTextBox = myRenamingTextBox; renamingTextBox.Bounds = bounds; renamingTextBox.Location = bounds.Location; renamingTextBox.MinimumSize = renamingTextBox.MaximumSize = renamingTextBox.Size = bounds.Size; if (!renamingTextBox.Visible) { renamingTextBox.Visible = true; renamingTextBox.Focus(); } renamingTextBox.Invalidate(); } else { const TextFormatFlags textFormatFlags = TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter | TextFormatFlags.NoPrefix | TextFormatFlags.NoClipping; TextRenderer.DrawText(g, tabPage.Name, base.Font, bounds, SystemColors.WindowText, textFormatFlags); } }
private void RenameTab(DiagramTabPage tabPage) { if (tabPage != null) { InlineTabRenameTextBox renamingTextBox = myRenamingTextBox; if (renamingTextBox != null) { if (renamingTextBox.RenamingTabPage == tabPage) { // If we already have an InlineTabRenameTextBox for this tab page, do nothing return; } else { // If we already have an InlineTabRenameTextBox for a different tab page, save the changes and close it renamingTextBox.Close(true); } } myRenamingTextBox = new InlineTabRenameTextBox(this, tabPage); base.Invalidate(false); } }