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 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; } }}
-Matt
Thanks for looking into this and raising the issue with developer support. Setting the TabSize on the UltraTabControl is not an option for me. For now I'll just have to remove the Bold text, and possibly use Microsoft Sans Serif.
-Justin
I don't believe that there is a way to set the individual size for tab items, only for all the tabs; the TabSize property is on the control itself. This is why I suggested that this might not be an ideal solution since you will possible have a bunch of extra space on tabs with less text than other tabs.
Matt,
I don't mind setting the size myself as a workaround. Since I add all of my tabs programatically at run time, I need to find out the size of the UltraTab, and then add some constant to allow for the close button. I cannot find a size property for the individual UltraTabs. There's the FixedWidth property, but it defaults to 0, so that doesn't help me. Is there some way to access the UltraTab's size?
This definitely seems like a bug. I have forwarded this thread to Developer Support so that the issue can be resolved accordingly. In the meantime, you could certainly set the TabLayoutStyle to SingleRowFixed and set the TabSize property yourself, but this might not be a viable solution for you.