locked
Need to fill DrawPie figure with solid color. RRS feed

  • Question

  • I have this code:

            public void CreateGraphics1()
            {
                Graphics ggg = tabControl1.TabPages[2].CreateGraphics();
                Pen pen = new Pen(Color.White, 5.0F);
                ggg.DrawArc(pen, 60.0F, 60.0F, 200.0F, 200.0F, 0.0F, 90.0F);
                Pen pen1 = new Pen(Color.White, 2.0F);
                ggg.DrawPie(pen1, 120.0F, 200.0F, 190.0F, 190.0F, 30.0F, 50.0F);
                // x,y of the upper left corner of the bounding rectangle
                // width, height; start angle, sweep angle
                SolidBrush redBrush = new SolidBrush(Color.Red);
                Point point1 = new Point(120, 200);
                Point point2 = new Point(200, 50);
                Point point3 = new Point(250, 200);
                Point point4 = new Point(50, 150);
                Point[] points = { point1, point2, point3, point4 };
                ggg.FillClosedCurve(redBrush, points); 
            }     // CreateGraphics1

    As you can see I borrowed some of the lines, or perhaps all of them from MSDN. The rectangle drawing is done by a separate routine which is not shown.

    This is the picture I got:

    As you can see I want to fill the pie sector with red color. How can I do it sensibly? Now the figure and the color are mismatched

    Thanks, - MyCatAlex




    • Moved by CoolDadTx Wednesday, January 8, 2020 9:15 PM Winforms Related
    • Edited by MyCatAlex Wednesday, January 8, 2020 9:37 PM
    Wednesday, January 8, 2020 9:04 PM

Answers

  • Hi MyCatAlex,
    You can use Graphics.FillPie method to fill the interior of a pie section.
    Here is a code example.

    private void button1_Click(object sender, EventArgs e)
    {        
        Graphics g = tabControl1.TabPages[1].CreateGraphics();
        Brush b1 = new SolidBrush(Color.Red);
        g.FillPie(b1, 120.0F, 200.0F, 190.0F, 190.0F, 30.0F, 50.0F);
    
    }

    Best Regards,
    Daniel Zhang


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by MyCatAlex Thursday, January 9, 2020 1:46 PM
    Thursday, January 9, 2020 7:00 AM
  • CoolDad, I believe you made a mistake and I am very upset with your decision. There is no WIndows.Forms involved in my post. It is all about C# language and Graphics class. Please move it back where it belongs.

    - MyCatAlex

    I agree.

    Cool Dad I don't see why you move graphics out of the c# forum to this windows form forum.

    Who looks at this forum? Its like moving them to the off topic corn field never to be seen again. The code is c# not windows.forms.

    :)

    PS you moved another thread on drawing boxes today?

    • Edited by tommytwotrain Thursday, January 9, 2020 11:15 PM
    • Marked as answer by MyCatAlex Friday, January 10, 2020 12:08 AM
    Thursday, January 9, 2020 11:15 PM

All replies

  • CoolDad, I believe you made a mistake and I am very upset with your decision. There is no WIndows.Forms involved in my post. It is all about C# language and Graphics class. Please move it back where it belongs.

    - MyCatAlex

    Wednesday, January 8, 2020 10:35 PM
  • Try this:

     

    using( var gp = new GraphicsPath( ) )
    {
       gp.AddPie( 120.0F, 200.0F, 190.0F, 190.0F, 30.0F, 50.0F );
       ggg.FillPath( Brushes.Red, gp );
       ggg.DrawPath( pen1, gp );
    }
    

     

    Thursday, January 9, 2020 6:05 AM
  • Hi MyCatAlex,
    You can use Graphics.FillPie method to fill the interior of a pie section.
    Here is a code example.

    private void button1_Click(object sender, EventArgs e)
    {        
        Graphics g = tabControl1.TabPages[1].CreateGraphics();
        Brush b1 = new SolidBrush(Color.Red);
        g.FillPie(b1, 120.0F, 200.0F, 190.0F, 190.0F, 30.0F, 50.0F);
    
    }

    Best Regards,
    Daniel Zhang


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by MyCatAlex Thursday, January 9, 2020 1:46 PM
    Thursday, January 9, 2020 7:00 AM
  • Worked like a charm. Many thanks, - MyCatAlex

    Thursday, January 9, 2020 1:47 PM
  • CoolDad, I believe you made a mistake and I am very upset with your decision. There is no WIndows.Forms involved in my post. It is all about C# language and Graphics class. Please move it back where it belongs.

    - MyCatAlex

    I agree.

    Cool Dad I don't see why you move graphics out of the c# forum to this windows form forum.

    Who looks at this forum? Its like moving them to the off topic corn field never to be seen again. The code is c# not windows.forms.

    :)

    PS you moved another thread on drawing boxes today?

    • Edited by tommytwotrain Thursday, January 9, 2020 11:15 PM
    • Marked as answer by MyCatAlex Friday, January 10, 2020 12:08 AM
    Thursday, January 9, 2020 11:15 PM