Reputation: 528
I'm developing a browser relying on webbrowser
winform component.
I used xtratabcontrol
in order to surf with tabs (DevExpress component) which has close button in its tabs.
I'm trying to achieve what internet explorer(its last version) does when closing a tab ; the other tabs are extended(their width increases) to reach the mouse poisiton (to enable closing tab after tab without moving the mouse)
this is the code which I added ( in close button click event)
Point cursor = MousePosition;
int x = cursor.X;
int count = browserTabControl.TabPages.Count -1;// I don't want to include the last tab (which opens another tabs)
int width = x / count;
for (int i = 0; i < browserTabControl.TabPages.Count -1 ; i++)
browserTabControl.TabPages[i].TabPageWidth = width;
I also tried to get the tabs whole width before removing the last tab, then to divide it on the new tabs count , and to set the result to each tab :
int current_width = (browserTabControl.TabPages.Count - 1) * browserTabControl.TabPages[0].TabPageWidth;
//..............some code removing the last tab (actually the tab before the last tab)
//after removing the last tab
int count = browserTabControl.TabPages.Count - 1;
int width = current_width / count;
for (int i = 0; i < browserTabControl.TabPages.Count - 1; i++)
browserTabControl.TabPages[i].TabPageWidth = width;
the first code result
the second code result :
Probably the problem is when I divide int/int I lose the rest of the division, I can get a double result , but the TabPageWidth is int.
Upvotes: 0
Views: 368
Reputation: 17850
Try the following solution:
// Initialization
foreach(XtraTabPage page in xtraTabControl.TabPages) {
if(page == addNewTabPage) continue;
page.TabPageWidth = 100; // turn off headers auto-size
}
}
void xtraTabControl_CloseButtonClick(object sender, EventArgs e) {
ClosePageButtonEventArgs ea = e as ClosePageButtonEventArgs;
if(ea.Page != addNewTabPage) {
xtraTabControl.BeginUpdate();
((XtraTabPage)ea.Page).Dispose();
int totalWidth = 0;
var visiblePages =((IXtraTab)xtraTabControl).ViewInfo.HeaderInfo.VisiblePages;
int totalHeadersGrow = 0;
for(int i = 0; i < visiblePages.Count; i++) {
var pageInfo = visiblePages[i];
if(pageInfo.Page == addNewTabPage) continue;
totalWidth += pageInfo.Bounds.Width;
totalHeadersGrow += (pageInfo.Bounds.Width - pageInfo.Page.TabPageWidth);
}
int count = xtraTabControl.TabPages.Count - 1;
int width = totalWidth / count - totalHeadersGrow / (count + 1);
foreach(XtraTabPage page in xtraTabControl.TabPages) {
if(page == addNewTabPage) continue;
page.TabPageWidth = width;
}
xtraTabControl.EndUpdate();
}
}
P.S. You can contact DevExpress support directly (and I believe that this is the best way when running into issues when using their product) to get official answer in this regard.
Upvotes: 1
Reputation: 73462
You can use HeaderAutoFill
feature for this. which will automatically fill the tabs to the client area; so there is no need for the user to move the mouse for closing multiple
this.xtraTabControl1.HeaderAutoFill = DevExpress.Utils.DefaultBoolean.True;
Upvotes: 0