Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good day please i am building a cbt app, i built a tabcontrol,tabpage,label and radio button from scratch but i want the tabcontrol to be red but whenever i click the radio button the tabcontrol should be green but i am confused because the tab control only get colored if i use the drag and drop tabcontrol

What I have tried:

   TabControl tabControl = new TabControl();
       //i have made the tabcontrol  draw mode to be ownerdrawfixed
        private void tabControl_DrawItem(object sender, DrawItemEventArgs e)
        {//this is to color my tabcontrol but nothing happens,it only works if i use drag and drop tabcontrol 
            Brush txt, box_brush;
            Pen bp;
            Rectangle tab_rect = tabControl.GetTabRect(e.Index);
            if (e.State == DrawItemState.Selected)
            {
                e.Graphics.FillRectangle(Brushes.Red, tab_rect);
                e.DrawFocusRectangle();

                txt = Brushes.Black;
                box_brush = Brushes.Silver;
                bp = Pens.DarkBlue;
            }
            else
            {
                e.Graphics.FillRectangle(Brushes.Red, tab_rect);
                txt = Brushes.Blue;
                box_brush = Brushes.Silver;
                bp = Pens.DarkBlue;
            }
        

//BUT I CREATED THE BUTTON UNDER BTNQUESTION
    public void btnquestion_Click(object sender, EventArgs e)
        {
                     
              this.Controls.Add(tabControl);
            int page;
//am= amount of the questions
            int am=20;
             for (int i = 0; i < am; i++)
               {
                  TabPage tp = new TabPage();
                page = i + 1;
                tp.Text = page.ToString();

                tabControl.Controls.Add(tp);
                 
                Label lb1 = new Label();
           RadioButton r1 = new RadioButton(); 
            RadioButton r2 = new RadioButton();
           RadioButton r3 = new RadioButton();
           RadioButton r4 = new RadioButton();
//i have done the locations and the font
                  tp.Controls.Add(lb1);
                    tp.Controls.Add(r1);
                    tp.Controls.Add(r2);
                    tp.Controls.Add(r3);
                    tp.Controls.Add(r4);
        
        }
Posted
Updated 3-Oct-17 2:13am
v4
Comments
Graeme_Grant 28-Sep-17 23:29pm    
Is your question:

"When the Radio button is clicked, it should change the TabControl Background Color but nothing happens. How do I make this work?"
akinwunmi 2-Oct-17 17:04pm    
yes thanks
Karthik_Mahalingam 29-Sep-17 1:14am    
Use Improve question to add more info to the question.

1 solution

Check it out, this might help you: Coloring Tab Control[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900