locked
Draw 2 Circle and connects circles at the circumference of the circle RRS feed

  • Question

  • Hello experts Please Help
    I have a Problem I am Drawing 2 Circle Using C# Graphics . 

    I want to add a Line Between them How do i do that My code Is Below

    protected override void OnPaint(PaintEventArgs e)
    {
    using (Graphics dc = this.CreateGraphics())//data Context
    {
    Rectangle ellipseArea1 = new Rectangle(0, 0, 200, 200);
    Rectangle ellipseArea2 = new Rectangle(0, 300, 200, 200);

    StringFormat stringFormat = new StringFormat();
    stringFormat.Alignment = StringAlignment.Center;
    stringFormat.LineAlignment = StringAlignment.Center;

    Pen greenPen = new Pen(Color.Green, BorderWidth);
    Pen bluePen = new Pen(Color.Blue, BorderWidth);

    float[] dashValues = { 2 ,2, 2, 2 };
    Pen darkBluePen = new Pen(Color.DarkBlue, BorderWidth);
    //darkBluePen.DashPattern = dashValues;


    Brush redBrush = new SolidBrush(Color.Red);
    Brush yellowBrush = new SolidBrush(Color.Yellow);

    Brush textBrush1 = new SolidBrush(Color.Black);
    Brush textBrush2 = new SolidBrush(Color.Brown);

    dc.DrawEllipse(greenPen, ellipseArea1);
    dc.FillEllipse(redBrush, ellipseArea1);// Filling Circle with Red Brush
    dc.DrawString("Circle1", new Font("Arial", 12), textBrush1, ellipseArea1, stringFormat);


    dc.DrawEllipse(bluePen, ellipseArea2);
    dc.FillEllipse(yellowBrush, ellipseArea2);// Filling Circle with Yellow Brush
    dc.DrawString("Circle2", new Font("Arial", 12), textBrush2, ellipseArea2, stringFormat);


    base.OnPaint(e);

    greenPen.Dispose();
    bluePen.Dispose();

    redBrush.Dispose();
    yellowBrush.Dispose();
    textBrush1.Dispose();
    textBrush2.Dispose();

    }
    }

     

    Tuesday, June 18, 2013 6:31 AM

Answers

  • Not sure if this is what you want, but there you go.

    Add this to the end of your code:

      Point p1 = new Point(0,250);
      Point p2 = new Point(200,250);

    dc.DrawLine(new Pen(Color.Black), p1, p2);


    • Proposed as answer by Barry Wang Thursday, June 20, 2013 10:44 AM
    • Marked as answer by Barry Wang Thursday, June 27, 2013 8:25 AM
    Tuesday, June 18, 2013 9:27 AM