Draw on a wmf file : MetaFile WMF « 2D Graphics « VB.Net Tutorial






Imports System.Drawing.Imaging
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms

public class DrawOnWMFFile
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class

public class Form1
  Inherits System.Windows.Forms.Form

  Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
        Dim curMetafile As Metafile = Nothing
        Dim g As Graphics = Me.CreateGraphics()

        Dim hdc As IntPtr = g.GetHdc()

        Dim rect As New Rectangle(0, 0, 200, 200)

        curMetafile = New Metafile("newFile.wmf", hdc)


        Dim g1 As Graphics = Graphics.FromImage(curMetafile)

        g1.SmoothingMode = SmoothingMode.HighQuality

        g1.FillRectangle(Brushes.Green, rect)
        rect.Y += 110

        Dim lgBrush As New LinearGradientBrush(rect, Color.Red, Color.Blue, 45.0F)
        g1.FillEllipse(lgBrush, rect)

        rect.Y += 110
        g1.DrawString("MetaFile Sample", New Font("Verdana", 20), lgBrush, 200, 200, StringFormat.GenericTypographic)

        g.ReleaseHdc(hdc)
        g1.Dispose()
        g.Dispose()

  End Sub

  Public Sub New()
   
    MyBase.New()
    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    Me.ClientSize = New System.Drawing.Size(292, 273)
    Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen

  End Sub

End Class








17.74.MetaFile WMF
17.74.1.Make Metafile (WMF)Make Metafile (WMF)
17.74.2.Create a Metafile
17.74.3.Draw a meta wmf file
17.74.4.Draw on a wmf file
17.74.5.Set EnumerateMetafileProc property