namespace WindowsFormsApp2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Bitmap pic = new Bitmap(50, 50); Graphics bg = Graphics.FromImage(pic); bg.DrawLine(new Pen(Color.Red, 2),10, 10, 30, 30); pictureBox1.Image = pic; } } }