// Desabilita as tab_pages
(tbcPublicacoes.TabPages[1] as Control).Enabled = false;
(tbcPublicacoes.TabPages[2] as Control).Enabled = false;
(tbcPublicacoes.TabPages[3] as Control).Enabled = false;
(tbcPublicacoes.TabPages[4] as Control).Enabled = false;
private void Form1_Load(object sender, EventArgs e) {
// set tabpages you want as disabled
(tabControl1.TabPages[1] as Control).Enabled = false;
// owner drawn items to give the impression of really being disabled
tabControl1.DrawMode = TabDrawMode.OwnerDrawFixed;
tabControl1.DrawItem += new DrawItemEventHandler(tabControl1_DrawItem);
// do not allow the disabled tabs to be selected
tabControl1.Selecting += new TabControlCancelEventHandler(tabControl1_Selecting);
}
void tabControl1_DrawItem(object sender, DrawItemEventArgs e) {
TabControl tc = (TabControl)sender;
TabPage tp = tc.TabPages[e.Index];
Graphics gr = e.Graphics;
Rectangle rect = e.Bounds;
// draw background, color depends on selected item or not
Brush bg = (e.State == DrawItemState.Selected) ? Brushes.White : new System.Drawing.Drawing2D.LinearGradientBrush(rect, Color.FromArgb(255, 241, 241, 241), Color.FromArgb(255, 206, 206, 206), System.Drawing.Drawing2D.LinearGradientMode.Vertical);
gr.FillRectangle(bg, rect);
// draw tab name, color depends on disabled or not
string txt = tp.Text;
Color col = tp.Enabled ? tp.ForeColor : Color.Gray; // normal / 'disabled'
rect.Offset(0, 3);
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Center;
gr.DrawString(txt, tp.Font, new SolidBrush(col), rect, sf);
}
private void tabControl1_Selecting(object sender, TabControlCancelEventArgs e) {
// if tab page is disabled, then cancel the selection event
if (e.Action == TabControlAction.Selecting && !e.TabPage.Enabled) {
e.Cancel = true;
}
}
Here is a little preview: //Include data
publicacaoBLL.Incluir(_publicacao);
// Inform success
MessageBox.Show("Book Included.", "Incluir", MessageBoxButtons.OK, MessageBoxIcon.Information);
// So, the 2nd tab page must be enabled
(tbcPublicacoes.TabPages[1] as Control).Enabled = true;
The TabPages of the TabControl can not be made unselectable only the controls on the specific page can all be made unselectable. Once a TabPage is part of the TabControl TabPage collection it will be displayed. What you can do is have a class level variable of type TabPage assign the page to that variable and remove it from the TabControl TabPages collection. This will cause the TabPage not to show at all. Not what you may want but only way I know to do what I think you want.