C# Windows Form

Posted on 2006-04-07
Last Modified: 2010-08-05
Is there a way to create a control that has tabs that appear to extend beyond the boundaries of the control?
Question by:tsmolskow
    LVL 48

    Expert Comment

    What about using TabControl?

    Expert Comment

    Try placing a Panel container on the form with AutoScroll set to true - this will give you scrollbars if a child extends
    beyond the size of the panel. Next add a child TabPanel to it and set whatever with and height you need it to be.
    LVL 5

    Expert Comment

    What you should actually do
    is make ur comtrol bigger
    and override the OnPaint method
    and paint the tabs urself
    that way - you can get transparency on the top of the control (where it collides with the background form)
    and you can turn it on / off by simply not painting anything there.


    Author Comment

    Sounds cool, can you give me a code example for the override on Paint method?
    LVL 5

    Accepted Solution

    Ok, but its a very simple

    A. Create a new windows form project
    B. Add a UserControl file
    C. Add a button to the user control
    D. Add the following code to the user control:
                protected override void OnPaint(PaintEventArgs e)
                      base.OnPaint (e);

                      if( m_DrawBox )
                            using( Brush fill = new SolidBrush(Color.Gray) )
                                  e.Graphics.FillRectangle(fill, 5, 5, 100, 100);

                            using( Pen border = new Pen(Color.Black) )
                                  e.Graphics.DrawRectangle( border, 5, 5, 100, 100 );

                private void button1_Click(object sender, System.EventArgs e)
                      m_DrawBox = !m_DrawBox;
                      this.Invalidate( true );
    E. Set the buttons Click event to point to the function
    F. Build the project
    G. Add the control to your form
    H. Run!

    Have fun

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Suggested Solutions

    This article is filled with multiple code samples and explanations for mathematical calculations. They are as follows: 1. General tips 2. Quadratic formula 3. Object collision 4. Projectile path General Tips       Here are some of my tips f…
    INTRODUCTION We all know how to code. But at times you simply want to insert a common code block into your existing code and amend it as per your requirements. This tool not only saves you time but also saves you the pain of typing it all out aga…
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now