Tab Page Header Location

大兔子大兔子 提交于 2019-12-12 02:27:00

问题


I have a Tab Control in my Form and what I want to achieve is a simple way to get the exact location the Tab Page Header.

I've searched around, but I haven't found anything. Any ideas?


回答1:


This will make the Tab control blink a little but it will return a list of bounding Rectangles for the pages' headers..

SortedDictionary<int, Rectangle> GetTabBounds(TabControl tab)
{
    SortedDictionary<int, Rectangle> bounds = new SortedDictionary<int, Rectangle>();
    TabDrawMode tdm = tab.DrawMode;
    tabControl1.DrawMode = TabDrawMode.OwnerDrawFixed;
    DrawItemEventHandler mit = (sl, el) => bounds.Add(el.Index, el.Bounds);
    tab.DrawItem += mit;
    tab.Refresh();
    tab.DrawItem -= mit;
    tab.DrawMode = tdm;
    tab.Invalidate();
    return bounds;
}

For a less exact result you may simply want to calculate them from the page index and tab item size..at least if your pages are all in one row.



来源:https://stackoverflow.com/questions/30399467/tab-page-header-location

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!