I have an UltraTabControl with the close button on the tab, and TabLayoutStyle set to SingleRowAutoSize. My problem is that the tabs are not auto sizing properly to allow for the close button, and the tab's text is being truncated. In the attached image, the tab show should read "ATS_DEV" with the close button after it. Instead it reads "ATS_D...". How can I get the autosize to take the close button into account? I am using the latest 8.3 hotfix.
Thanks,
Justin
Justin,
I was unable to reproduce this behavior using a TabOrientation of LeftTop, a Style of Excel, and a couple tabs. Are there any other properties that you have set? If you can reproduce this in a simple sample and attach it to your reply, I can take a look at it since you said that you already have the latest 8.3 hotfix.
-Matt
Matt,
Thanks for looking into this. It can be reproduced by setting the main form's Font to 'Verdana', and setting the UltraTabControl.Appearance.FontData.Bold to True. Attached is a small example.
-Justin
I was able to hack around this for now with a creation filter. Keep in mind that, since this was a fairly quick hack, it won't really dynamically adjust to any appearances that you set on the tab itself that might affect the font size, but it may be good enough for you for now until a real fix is made:
public partial class Form1 : Form { public Form1() { InitializeComponent(); this.ultraTabControl1.CreationFilter = new TabCreationFilter(this); } private Graphics cachedGraphics; private Graphics CachedGraphics { get { if (this.cachedGraphics == null) this.cachedGraphics = this.CreateGraphics(); return this.cachedGraphics; } } protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); if (this.cachedGraphics != null) this.cachedGraphics.Dispose(); } base.Dispose(disposing); } private class TabCreationFilter : IUIElementCreationFilter { private Form1 form; public TabCreationFilter(Form1 form) { this.form = form; } public void AfterCreateChildElements(UIElement parent) { TabItemUIElement tabElem = parent as TabItemUIElement; if (tabElem != null) { UltraTab tab = tabElem.TabItem as UltraTab; if (tab != null) { UIElement textElem = tabElem.GetDescendant(typeof(ImageAndTextUIElement.ImageAndTextDependentTextUIElement)); if (textElem != null) { SizeF textSize = this.form.CachedGraphics.MeasureString(tab.Text, this.form.Font); int requiredHeight = Size.Ceiling(textSize).Width + 6; // AdHoc testing showed that we needed 6 more int heightDiff = requiredHeight - textElem.RectInsideBorders.Height; if (heightDiff > 0) { Rectangle tabRect = tabElem.Rect; tabElem.Rect = new Rectangle(tabRect.Location, new Size(tabRect.Width, tabRect.Height + heightDiff)); } } } } } public bool BeforeCreateChildElements(UIElement parent) { return false; } }}
Thanks for providing that workaround. I had to increase the extra buffer from 6 to 15 so that some of the longer tab captions would fit. It worked like a charm for fitting the text on the tab, but now the tabs are not spacing themselves properly on the tab strip. They are bunching together. I think I may just go with using a different font and removing the bold text property. I think this is the all around easiest workaround until the bug is fixed. Thank you for your efforts.
I didn't have enough time to test the workaround thoroughly, but should you decide to play around further with it, I think that the problem is that you need to manually adjust the rects of any tab elements that are below the one you repositioned. You could keep track of the last bottom edge and set the next tab element's rect accordingly. I had thought of this when writing the creation filter, but it didn't manifest itself in my test.
Hi Matt,
Do you have any news regarding this problem? Using 9.2 I have the same problem as JWJones.
My guess is that it's not yet fixed, but could you suggest some workaround, other than using filters?
Thank you.
This was ultimately determined to be not a bug. In the sample provided by JWJones, the Bold value was being set on an individual tab. However, tab metrics are not calculated with the Fonts on individual tabs for performance reasons. The tab metrics are measured with the Fonts on the Appearance, ActiveTabAppearance, and SelectedTabAppearance of the UltraTabControl and the widest calculated tab width is used. So you can prevent the ellipses from appearing by setting the Bold value on one of those three appearances.
I had a similar problem and I found that If I set the FixedWidth property of the tab to a really large number (I did 200) and then right after that call .ResetFixedWidth() on the tab, it would reset it to the right size.