Draw Shelf by creating Bitmap - CSharp System.Drawing

CSharp examples for System.Drawing:Graphics

Description

Draw Shelf by creating Bitmap

Demo Code


using System.Threading.Tasks;
using System.Text;
using System.Linq;
using System.Drawing;
using System.Collections.Generic;
using System;/*ww w  . ja va  2s  . c  o m*/

public class Main{
        public static Image DrawShelf(Size size, Color color)
        {
            Bitmap bitmap = new Bitmap(size.Width, size.Height);
            bitmap.MakeTransparent();
            Graphics g = Graphics.FromImage(bitmap);
            Pen pen = new Pen(color, 1);
            Point start = new Point();
            Point end = new Point();
            for (int i = 0; i < 9; i++)
            {
                start.X = 41 * i;
                start.Y = 0;
                end.X = 41 * i;
                end.Y = size.Height;
                g.DrawLine(pen, start, end);

                start.X = 0;
                start.Y = 41 * i;
                end.X = size.Width;
                end.Y = 41 * i;
                g.DrawLine(pen, start, end);
            }
            return bitmap;
        }
}

Related Tutorials