Create Metafile (Reload) : wmf file « 2D Graphics « C# / C Sharp






Create Metafile (Reload)

 
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Windows.Forms;

class CreateMetafileReload : Form {
    const string strMetafile = "CreateMetafileReload.emf";

    public static void Main() {
        Application.Run(new CreateMetafileReload());
    }
    public CreateMetafileReload() {
        ResizeRedraw = true;

        if (!File.Exists(strMetafile)) {
            Graphics grfx = CreateGraphics();
            IntPtr ipHdc = grfx.GetHdc();

            Metafile mf = new Metafile(strMetafile, ipHdc);

            grfx.ReleaseHdc(ipHdc);
            grfx.Dispose();

            grfx = Graphics.FromImage(mf);

            grfx.DrawEllipse(Pens.Black, 0, 0, 100, 100);
            grfx.FillEllipse(Brushes.Blue, 60, 20, 20, 20);
            grfx.DrawArc(new Pen(Color.Red, 10), 20, 20, 60, 60, 30, 120);
            grfx.Dispose();
        }
    }
    protected override void OnPaint(PaintEventArgs pea) {
        DoPage(pea.Graphics, ForeColor, ClientSize.Width, ClientSize.Height);
    }
    protected void DoPage(Graphics grfx, Color clr, int cx, int cy) {
        Metafile mf = new Metafile(strMetafile);

        for (int y = 0; y < cy; y += mf.Height)
            for (int x = 0; x < cx; x += mf.Width)
                grfx.DrawImage(mf, x, y, mf.Width, mf.Height);
    }
}

 








Related examples in the same category

1.Enumerate Metafile
2.Metafile Page Units
3.Create Metafile (Memory)
4.Create Metafile