How do I draw circles, rectangles, lines and text

Handle the Paint event for your control or form. private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { Graphics g = e.Graphics; Pen pen = new Pen(Color.White, 2); SolidBrush redBrush = new SolidBrush(Color.Red); g.DrawEllipse(pen, 100,150,100,100); g.DrawString(‘Circle’, this.Font, redBrush, 80, 150); g.FillRectangle(redBrush, 140, 35, 20, 40); g.DrawString(‘Rectangle’, this.Font, redBrush, 80, 50); g.DrawLine(pen, 114, 110, 150, 110); g.DrawString(‘Line’, this.Font, redBrush, 80, 104); }

How can I decorate a button face with custom drawing

Subclass Button and add a custom Paint event handler that does you custom drawing. public class MyButton : System.Windows.Forms.Button { public MyButton() { this.Paint += new System.Windows.Forms.PaintEventHandler(this.button1_Paint); } private void button1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { //custom drawing Pen pen2 = new Pen(Color.Red); pen2.Width = 8; e.Graphics.DrawLine(pen2, 7, 4, 7, this.Height – 4); pen2.Width = 1; e.Graphics.DrawEllipse(pen2, this.Width – 16 , 6, 8, 8); } }

How do I overlay one bitmap over another

You can create a Graphics object from the base bitmap, and then use this Graphics object to draw the second bitmap with a transparent color that allows the base bitmap to show through. Bitmap Circle = (Bitmap)Image.FromFile(@’c:\circle.bmp’); Bitmap MergedBMP = (Bitmap)Image.FromFile(@’c:\cross.bmp’); Graphics g = Graphics.FromImage(Circle); MergedBMP.MakeTransparent(Color.White); g.DrawImage(MergedBMP,0,0); g.Dispose(); pictureBox1.Image = Circle;