rreeves rreeves - 1 month ago 24
C# Question

Remove tab from tabpages from current tab

I have a tabcontrol from my mainform that I add user controls too. I want to be able to remove the tab from the collection from within itself. Maybe put a little x on the corner. How do you think I would go about doing that ?

This is how I add stuff to the TabPage control.

DevExpress.XtraTab.XtraTabPage tabPage = new DevExpress.XtraTab.XtraTabPage() { Text = room.Name, Tag = roomView };

roomView.ParentTab = tabPage;
roomView.Dock = DockStyle.Fill;
roomView.Settings = Settings;

tabPage.Controls.Add(roomView);
tbRooms.TabPages.Add(tabPage);

Answer

Put the "x" button out there, assign an event to it, then in the click event call something like this:

tbRooms.TabPages.Remove(tbRooms.SelectedTab);

Something like that should work.