C# .NET - graphics

Asked By John Watts
03-Nov-09 06:15 PM

I am writing a graphics program where I have to make a circle go across a rectangle stop at the end of the rectangle and then turn and go back.  How do I get it to go back?

 

Thank you

re  re

03-Nov-09 10:45 PM

DrawEllipse method is used to draw ellipse or circle.

protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics ;
Pen pen = new Pen( Color.Black,3 );
Rectangle rect = new Rectangle(4, 4, 100, 100);
g.DrawEllipse( pen, rect );
}

u can draw rectangle as follows

C# code to draw a Rectangle

http://www.eggheadcafe.com/tutorials/aspnet/387702a9-0a40-43a4-9e82-6f6d8eb86205/c-graphics--a-gdi-worl.aspx

http://www.homeandlearn.co.uk/csharp/csharp_s15p2.html

Create New Account
help
using jQuery http: / / www.andytimney.com / ?p = 65 you need MultiSelection DropdownList noTitle body { background-color: #FFFFFF; white-space: nowrap; } span.s0 { font-family: "Courier New"; font-size: 9.75pt; color: #000000; background-color: #FFFFFF; } span.s1 { font-family: "Courier New"; font-size: 10pt; color: #008000; background color: #FFFFFF; } span.s2 { font-family: "Courier New"; font-size: 10pt; color: #008000; background-color: #FFFFFF; } span.s3 { font-family: "Courier New"; font-size: 10pt; color: #008000; background-color: #FFFFFF; } span.s4 { font-family: "Courier New"; font-size: 10pt; color: #FFA500
for drawing circle on rectangle code for drawing circle on rectangle in .net? hi, here is the code for you 1. / * 2. * Created using SharpDevelop free 38. rnd = new Random((int)DateTime.Now.Ticks); / / seeded with ticks 39. myPen = new Pen(Color.Red); 40. } 41. 42. / / Clean up any resources being used 43. protected override void Dispose Line button click event 138. private void btnLine_Click(object sender, System.EventArgs e) 139. { 140. Graphics xGraph; 141. int k; 142. 143. xGraph = Graphics.FromImage(DrawArea); 144. 145. for(k = 1; k < 40; k++) 146. { 147. myPen.Color = Color.FromArgb( 148. (rnd.Next(0, 255)), 149. (rnd.Next(0, 255)), 150. (rnd.Next(0 Circle button click event 164. private void btnCircle_Click(object sender, System.EventArgs e) 165. { 166. Graphics xGraph; 167. int k; 168. int r; / / radius of circle 169. int x, y; / / center
Bttn_Reset_Click( object sender, EventArgs e) { System.Drawing.Pen myPen = new System.Drawing.Pen(System.Drawing.Color.Red); System.Drawing.Graphics formGraphics; formGraphics = this .CreateGraphics(); formGraphics.DrawLine(myPen, 0, 0, 200, 200); myPen.Dispose(); formGraphics.Dispose(); } private void DialsForm_Paint_1( object sender, PaintEventArgs e) { Graphics g = e.Graphics; Pen mypen = new Pen Color.Black, 2); SolidBrush mybrush = new SolidBrush(Color.Blue); / / g.FillEllipse(mybrush, 10, 50, 150, 150); g.DrawEllipse(mypen, 20, 20, 100, 100); g.DrawEllipse(mypen, 140, 20, 100, 100); g.DrawEllipse(mypen, 260, 20, 100, 100); g.DrawEllipse(mypen
Round rectangles, fonts and ellipse in C# using GDI. You will need to use below graphics namespaces in windows application: using System.Drawing; using System.Drawing.Drawing2D; Complete Program: After creating windows application copy paste below code in your main code using System; using WindowsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } protected override void OnPaint(PaintEventArgs e) { Graphics objG = e.Graphics; Pen objP = new Pen(Color.Blue); Font font = new Font( "Times New Roman" , 26); / / draw eclipse Rectangle rect = new Rectangle(50, 50, 200, 100); objG.DrawEllipse(objP, rect); objG.DrawString( "EggHeadCafe" , font, new SolidBrush(Color.Red), 14, 10); / / draw round rectangle