?
Solved

how can i fill color in my tab control which i have marked with red line ??

Posted on 2011-02-28
4
Medium Priority
?
307 Views
Last Modified: 2012-05-11
i want to know that how can i fill color in my tab control which i have marked with red line ??

please refer the attached snapshot ....

tell me what can i do now ??

give me some suggestions ....

28-02-2011-6-14-27-PM.jpg
0
Comment
Question by:Parth48
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 13

Accepted Solution

by:
Naman Goel earned 2000 total points
ID: 34996664
use DrawMode = TabDrawMode.OwnerDrawFixed;

and using DrawItem you can paint in whatever way you want

refer to following sample code for more details.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
    public partial class TestForm : Form
    {
        private TabControl tabControl1;
        private TabPage tabPage1;
        private RadioButton rbq1_d;
        private RadioButton rbq1_c;
        private RadioButton rbq1_b;
        private RadioButton rbq1_a;
        private Label label1;
        private TabPage tabPage2;
        private Color TabControlBackColor;
        private DataGridView dataGridView1;
        private DataGridViewTextBoxColumn serialnumber;
        private DataGridViewTextBoxColumn Value;
        private SolidBrush TabControlBrush = null;

    
        public TestForm()
        {
            

            InitializeComponent();
            tabControl1.DrawMode = TabDrawMode.OwnerDrawFixed;

            TabControlBackColor = Color.Blue;
            TabControlBrush = new SolidBrush(TabControlBackColor);

            foreach (TabPage page in tabControl1.TabPages)
            {
                page.BackColor = TabControlBackColor;
            }
            
            dataGridView1.Rows.Add( "1", null,"2", null );
            
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                TabControlBrush.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
            this.tabControl1 = new System.Windows.Forms.TabControl();
            this.tabPage1 = new System.Windows.Forms.TabPage();
            this.rbq1_d = new System.Windows.Forms.RadioButton();
            this.rbq1_c = new System.Windows.Forms.RadioButton();
            this.rbq1_b = new System.Windows.Forms.RadioButton();
            this.rbq1_a = new System.Windows.Forms.RadioButton();
            this.label1 = new System.Windows.Forms.Label();
            this.tabPage2 = new System.Windows.Forms.TabPage();
            this.dataGridView1 = new System.Windows.Forms.DataGridView();
            this.serialnumber = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Value = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.tabControl1.SuspendLayout();
            this.tabPage1.SuspendLayout();
            this.tabPage2.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
            this.SuspendLayout();
            // 
            // tabControl1
            // 
            this.tabControl1.Controls.Add(this.tabPage1);
            this.tabControl1.Controls.Add(this.tabPage2);
            this.tabControl1.Location = new System.Drawing.Point(13, 13);
            this.tabControl1.Name = "tabControl1";
            this.tabControl1.SelectedIndex = 0;
            this.tabControl1.Size = new System.Drawing.Size(254, 203);
            this.tabControl1.TabIndex = 0;
            this.tabControl1.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.tabControl1_DrawItem);
            // 
            // tabPage1
            // 
            this.tabPage1.BackColor = System.Drawing.SystemColors.Control;
            this.tabPage1.Controls.Add(this.rbq1_d);
            this.tabPage1.Controls.Add(this.rbq1_c);
            this.tabPage1.Controls.Add(this.rbq1_b);
            this.tabPage1.Controls.Add(this.rbq1_a);
            this.tabPage1.Controls.Add(this.label1);
            this.tabPage1.Location = new System.Drawing.Point(4, 22);
            this.tabPage1.Name = "tabPage1";
            this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
            this.tabPage1.Size = new System.Drawing.Size(246, 177);
            this.tabPage1.TabIndex = 0;
            this.tabPage1.Text = "Question1";
            // 
            // rbq1_d
            // 
            this.rbq1_d.AutoSize = true;
            this.rbq1_d.Location = new System.Drawing.Point(20, 133);
            this.rbq1_d.Name = "rbq1_d";
            this.rbq1_d.Size = new System.Drawing.Size(84, 17);
            this.rbq1_d.TabIndex = 4;
            this.rbq1_d.TabStop = true;
            this.rbq1_d.Text = "d. Comma (,)";
            this.rbq1_d.UseVisualStyleBackColor = true;
            // 
            // rbq1_c
            // 
            this.rbq1_c.AutoSize = true;
            this.rbq1_c.Location = new System.Drawing.Point(20, 110);
            this.rbq1_c.Name = "rbq1_c";
            this.rbq1_c.Size = new System.Drawing.Size(99, 17);
            this.rbq1_c.TabIndex = 3;
            this.rbq1_c.TabStop = true;
            this.rbq1_c.Text = "c. SemiColon (;)";
            this.rbq1_c.UseVisualStyleBackColor = true;
            // 
            // rbq1_b
            // 
            this.rbq1_b.AutoSize = true;
            this.rbq1_b.Location = new System.Drawing.Point(20, 87);
            this.rbq1_b.Name = "rbq1_b";
            this.rbq1_b.Size = new System.Drawing.Size(76, 17);
            this.rbq1_b.TabIndex = 2;
            this.rbq1_b.TabStop = true;
            this.rbq1_b.Text = "b. Colon (:)";
            this.rbq1_b.UseVisualStyleBackColor = true;
            // 
            // rbq1_a
            // 
            this.rbq1_a.AutoSize = true;
            this.rbq1_a.Location = new System.Drawing.Point(20, 64);
            this.rbq1_a.Name = "rbq1_a";
            this.rbq1_a.Size = new System.Drawing.Size(79, 17);
            this.rbq1_a.TabIndex = 1;
            this.rbq1_a.TabStop = true;
            this.rbq1_a.Text = "a. Period (.)";
            this.rbq1_a.UseVisualStyleBackColor = true;
            // 
            // label1
            // 
            this.label1.Location = new System.Drawing.Point(17, 8);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(211, 53);
            this.label1.TabIndex = 0;
            this.label1.Text = "1. what does it mean if you compile c# source code file and you only get copyrigh" +
                "t information about microsoft as response?";
            // 
            // tabPage2
            // 
            this.tabPage2.Controls.Add(this.dataGridView1);
            this.tabPage2.Location = new System.Drawing.Point(4, 22);
            this.tabPage2.Name = "tabPage2";
            this.tabPage2.Padding = new System.Windows.Forms.Padding(3);
            this.tabPage2.Size = new System.Drawing.Size(246, 177);
            this.tabPage2.TabIndex = 1;
            this.tabPage2.Text = "Question2";
            this.tabPage2.UseVisualStyleBackColor = true;
            // 
            // dataGridView1
            // 
            this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
            this.serialnumber,
            this.Value});
            dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
            dataGridViewCellStyle2.BackColor = System.Drawing.SystemColors.Window;
            dataGridViewCellStyle2.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            dataGridViewCellStyle2.ForeColor = System.Drawing.SystemColors.ControlText;
            dataGridViewCellStyle2.NullValue = "NULL";
            dataGridViewCellStyle2.SelectionBackColor = System.Drawing.SystemColors.Highlight;
            dataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
            dataGridViewCellStyle2.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
            this.dataGridView1.DefaultCellStyle = dataGridViewCellStyle2;
            this.dataGridView1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.dataGridView1.Location = new System.Drawing.Point(3, 3);
            this.dataGridView1.Name = "dataGridView1";
            this.dataGridView1.Size = new System.Drawing.Size(240, 171);
            this.dataGridView1.TabIndex = 0;
            // 
            // serialnumber
            // 
            this.serialnumber.HeaderText = "S. No.";
            this.serialnumber.Name = "serialnumber";
            // 
            // Value
            // 
            this.Value.HeaderText = "Name";
            this.Value.Name = "Value";
            // 
            // TestForm
            // 
            this.BackColor = System.Drawing.Color.Red;
            this.ClientSize = new System.Drawing.Size(292, 273);
            this.Controls.Add(this.tabControl1);
            this.KeyPreview = true;
            this.Name = "TestForm";
            this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.TestForm_KeyDown);
            this.tabControl1.ResumeLayout(false);
            this.tabPage1.ResumeLayout(false);
            this.tabPage1.PerformLayout();
            this.tabPage2.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
            this.ResumeLayout(false);

        }

        private void tabControl1_DrawItem(object sender, DrawItemEventArgs e)
        {
            e.Graphics.FillRectangle(TabControlBrush, new Rectangle(0, 0, tabControl1.Width, tabControl1.Height));
        }

        private void TestForm_KeyDown(object sender, KeyEventArgs e)
        {
            Application.Exit();
        }
    }
}

Open in new window

0
 

Author Comment

by:Parth48
ID: 35004308
hi @naman_goel:

my coding is below but i can't paint that red mark line which has been seen in attached snapshot....

private void tbQuestionBank_DrawItem(object sender, DrawItemEventArgs e)
        {
            TabPage currenttab = tbQuestionBank.TabPages[e.Index];
            tbQuestionBank.DrawMode = TabDrawMode.OwnerDrawFixed;
            Rectangle ItemRect = tbQuestionBank.GetTabRect(e.Index);
            SolidBrush FillBrush = new SolidBrush(Color.FromKnownColor(KnownColor.InactiveCaptionText));
            SolidBrush TextBrush = new SolidBrush(Color.Black);
            StringFormat sf = new StringFormat();
            sf.Alignment = StringAlignment.Center;
            sf.LineAlignment = StringAlignment.Center;

            //if we are currently painted the selected tab item then we can change the brush color
            if(System.Convert.ToBoolean(e.State & DrawItemState.Selected))
            {
                FillBrush.Color = Color.FromKnownColor(KnownColor.InactiveCaptionText);
                TextBrush.Color = Color.Black;
                ItemRect.Inflate(2,2);
            }
            //Set up rotation for left and right aligned tabs
            if (tbQuestionBank.Alignment == TabAlignment.Left || tbQuestionBank.Alignment == TabAlignment.Right)
            {
                float RotateAngle = 90;
                if (tbQuestionBank.Alignment == TabAlignment.Left)
                    RotateAngle = 270;
                PointF cp = new PointF(ItemRect.Left + (ItemRect.Width / 2), ItemRect.Top + (ItemRect.Height / 2));
                e.Graphics.TranslateTransform(cp.X, cp.Y);
                e.Graphics.RotateTransform(RotateAngle);
                ItemRect = new Rectangle(-(ItemRect.Height / 2), -(ItemRect.Width / 2), ItemRect.Height, ItemRect.Width);
            }

            //Next we'll paint the TabItem with our Fill Brush
            e.Graphics.FillRectangle(FillBrush, ItemRect);

            //Now draw the text.
            e.Graphics.DrawString(currenttab.Text, e.Font, TextBrush, (RectangleF)ItemRect, sf);

            //Reset any Graphics rotation
            e.Graphics.ResetTransform();

            //Finally, we should Dispose of our brushes.
            FillBrush.Dispose();
            TextBrush.Dispose();
        }

Open in new window


is there anything wrong in the above code ??
0
 

Author Comment

by:Parth48
ID: 35016024
i can't do it , can u please tell me how can i fill that red line marked area ??
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question