/* * A C# program that creates a custom component with its own renderer, * and demonstrates how to render stroke objects. * * Ben Bederson, January 30, 2002 */ using System; using System.Drawing; using System.Windows.Forms; public class BasicStroker : System.Windows.Forms.Form { static public void Main() { Application.Run(new BasicStroker()); } public BasicStroker() { Size = new Size(400, 400); StartPosition = FormStartPosition.CenterScreen; StrokeControl control = new StrokeControl(); control.Location = new Point(0, 0); control.Size = new Size(400, 400); Controls.Add(control); } } class StrokeControl : Control { static Pen redPen = new Pen(Color.Red); protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; BackColor = Color.White; redPen.LineJoin = System.Drawing.Drawing2D.LineJoin.Round; redPen.StartCap = System.Drawing.Drawing2D.LineCap.Round; redPen.EndCap = System.Drawing.Drawing2D.LineCap.Round; redPen.Width = 10; g.DrawRectangle(redPen, 10, 10, 100, 100); g.DrawLine(redPen, 50, 50, 200, 100); redPen.StartCap = System.Drawing.Drawing2D.LineCap.Flat; redPen.EndCap = System.Drawing.Drawing2D.LineCap.Flat; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; g.DrawLine(redPen, 200, 50, 50, 100); } }