Rotate your phone or change to desktop for better experience

Rotate your phone or change to desktop for better experience

4.Draw a square with sides 100 pixels in length. Then inscribe a circle of radius 50 inside the square. Position the square and the inscribed circle in the middle of the screen.

 using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

namespace drawGraphics

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

this.Text = "Drawing a rectangle inscribed with circle";

this.Size = new Size(450, 400);

this.Paint += new PaintEventHandler(Draw_Graphics);

}

public void Draw_Graphics(object sender, PaintEventArgs e)

{

System.Drawing.Graphics g;

g = this.CreateGraphics();

Pen p1 = new Pen(System.Drawing.Color.Red, 3);

Pen p2 = new Pen(System.Drawing.Color.Blue,3);

Rectangle r = new Rectangle(100, 100, 50, 50);

g.DrawRectangle(p1, r);

g.DrawEllipse(p2, 100, 100, 50,50);

}

private void Form1_Load(object sender, EventArgs e)

{

}

}

}

Post a Comment

0 Comments