How to join overlapping circles?

后端 未结 3 447
失恋的感觉
失恋的感觉 2021-02-02 11:18

I want to visually join two circles that are overlapping so that

\"AltText\"

becomes

3条回答
  •  太阳男子
    2021-02-02 12:05

    Now this will work 100% for you even the figure is ellipse and any number of figures

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Pen p = new Pen(Color.Red, 2);      
    
            Rectangle Fig1 = new Rectangle(50, 50, 100, 50);  //dimensions of Fig1
            Rectangle Fig2 = new Rectangle(100, 50, 100, 50); //dimensions of Fig2
            . . .
    
            DrawFigure(e.Graphics, p, Fig1);   
            DrawFigure(e.Graphics, p, Fig2);
            . . .
    
            //remember to call  FillFigure after  drawing all figures.
            FillFigure(e.Graphics, p, Fig1); 
            FillFigure(e.Graphics, p, Fig2);
            . . .
        }
        private void DrawFigure(Graphics g, Pen p, Rectangle r)
        {
            g.DrawEllipse(p, r.X, r.Y, r.Width, r.Height);
        }
        private void FillFigure(Graphics g, Pen p, Rectangle r)
        {
            g.FillEllipse(new SolidBrush(this.BackColor), r.X + p.Width, r.Y + p.Width, r.Width - 2 * +p.Width, r.Height - 2 * +p.Width);      //Adjusting Color so that it will leave border and fill 
        }
    

    alt text

提交回复
热议问题