using System.Windows.Forms; using System.Drawing; public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Graphics g = this.CreateGraphics(); g.DrawLine(Pens.Black, 0, 0, this.Width, this.Height); } }
using System.Windows.Forms; using System.Drawing; public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Graphics g = this.CreateGraphics(); g.DrawRectangle(Pens.Red, 10, 10, this.Width - 20, this.Height - 20); } }The System.Windows.Forms package library is used in these examples.