Private Sub btnMake_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnMake.Click
' Get a Graphics object representing the screen (for
' reference).
Dim gr As Graphics = Me.CreateGraphics()
' Get the Graphics object's hDC.
Dim hdc As IntPtr = gr.GetHdc()
' Make a metafile that can work with the hDC.
Dim mf As New Metafile(txtFile.Text, hdc, _
New Rectangle(0, 0, 210, 210), _
MetafileFrameUnit.Pixel)
' Make a Graphics object to work with the metafile.
Dim mf_gr As Graphics = Graphics.FromImage(mf)
' Draw on the metafile.
Dim the_pen As New Pen(Color.Blue, 5)
mf_gr.DrawRectangle(the_pen, 5, 5, 190, 190)
the_pen.Color = Color.Red
the_pen.Width = 10
mf_gr.DrawEllipse(the_pen, 20, 20, 160, 160)
Dim pts() As Point = { _
New Point(100, 40), _
New Point(160, 100), _
New Point(100, 160), _
New Point(40, 100) _
}
the_pen.Color = Color.Green
the_pen.Width = 3
mf_gr.DrawPolygon(the_pen, pts)
the_pen.Color = Color.Orange
the_pen.Width = 5
mf_gr.DrawLine(the_pen, 75, 75, 125, 125)
mf_gr.DrawLine(the_pen, 125, 75, 75, 125)
' Clean up.
mf_gr.Dispose()
mf.Dispose()
gr.ReleaseHdc(hdc)
gr.Dispose()
MessageBox.Show("Ok")
End Sub
|
Private Sub btnLoad_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnLoad.Click
Dim mf As New Metafile(txtFile.Text)
Dim bm As New Bitmap(mf.Width, mf.Height)
Dim gr As Graphics = Graphics.FromImage(bm)
gr.DrawImage(mf, 0, 0)
picMetafile.Image = bm
gr.Dispose()
End Sub
|