Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6858651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:11:10+00:00 2026-05-27T02:11:10+00:00

Pretty simple Question, unfortunatly never used draw controls etc in C# so im not

  • 0

Pretty simple Question, unfortunatly never used draw controls etc in C# so im not sure how to look at this.
Ok, im drawing a piechart from a bunch of textboxs for input and running the draw on a button event.
i need to draw the chart on one of my tabs instead of the from background. how do i set it?
heres my code:

      private void tempButton_Click(object sender, EventArgs e)
    {
        Rectangle tabArea;
        RectangleF tabTextArea;

        Bitmap B = new Bitmap(500, 500);

        tabArea = tabControl1.GetTabRect(0);

        tabTextArea = (RectangleF)tabControl1.GetTabRect(0);

        using (Graphics g = Graphics.FromImage(B))
        {
            int i1 = int.Parse(textBox1.Text);
            int i2 = int.Parse(textBox2.Text);
            int i3 = int.Parse(textBox3.Text);
            int i4 = int.Parse(textBox4.Text);

            float total = i1 + i2 + i3 + i4;
            float deg1 = (i1 / total) * 360;
            float deg2 = (i2 / total) * 360;
            float deg3 = (i3 / total) * 360;
            float deg4 = (i4 / total) * 360;

            Font font = new Font("Arial", 10.0f);
            SolidBrush brush = new SolidBrush(Color.Red);
            Pen p = new Pen(Color.Black, 2);
            p.Width = 0.5f;

            tabArea = new Rectangle(textBox1.Location.X + textBox1.Size.Width + 250, 150, 500, 500);

            Brush b1 = new SolidBrush(Color.Gold);
            Brush b2 = new SolidBrush(Color.Silver);
            Brush b3 = new SolidBrush(Color.DarkOrange);
            Brush b4 = new SolidBrush(Color.Black);

            g.DrawRectangle(p, tabArea);

            g.DrawPie(p, tabTextArea, 0, deg1);
            g.FillPie(b1, tabArea, 0, deg1);
            g.DrawPie(p, tabTextArea, deg1, deg2);
            g.FillPie(b2, tabArea, deg1, deg2);
            g.DrawPie(p, tabTextArea, deg2 + deg1, deg3);
            g.FillPie(b3, tabArea, deg2 + deg1, deg3);
            g.DrawPie(p, tabTextArea, deg3 + deg2 + deg1, deg4);
            g.FillPie(b4, tabArea, deg3 + deg2 + deg1, deg4);

            //set picturebox3 as data source??
            pictureBox3.Image = B;

        }
    }

As you can see when i click the test button it draws the chart but behind my tab area, i need it to draw onto one of my tabs(i got a feeling this is super easy 1line solution, but google is not my friend atm ).
Many thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:11:11+00:00Added an answer on May 27, 2026 at 2:11 am

    The simplest solution is to create a bitmap of the desired dimensions, create Graphics for this bitmap, do the drawing and then set this bitmap as the image source for an auto-sizing picture box you place on the tab. This is the cleanest way.

    UPDATE
    I noted in my comments that your drawing code is not well thought through. Change the first lines as follows:

        Rectangle tabArea;
        RectangleF tabTextArea;
    
        Bitmap B = new Bitmap(500, 500, PixelFormat.Format32bppArgb);
    
        tabArea = new Rectangle(0, 0, B.Width, B.Height);
        tabTextArea = new RectangleF(0, 0, B.Width, B.Height);
    

    Also: Determining tabArea based on control locations is not a good idea.
    Lastly: Set the “SizeMode” property to “AutoSize” to have the picture box stretch to the bitmap dimension.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This a pretty simple question, I'm just not sure how to do it exactly.
Pretty simple question, I'm writing an XML document and i'm not sure how to
This is a pretty simple question but I'm somewhat stumped. I am capturing sections
hopefully a pretty simple question this time. I have a Select method in a
This is a pretty simple question and I'm assuming the answer is It doesn't
I think this is a pretty simple question. How do you an apache rewrite
Pretty simple question, perhaps not so simple answer though: I've got a clear view
This is a pretty simple question. def func1 t2=Thread while true # if t2.alive?
This is probably a pretty simple question. In C# I'm trying to write a
This might be a pretty simple question, but if there really is a difference,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.