Home
Browse all 647 examples
Download all 647 examples
Download sample chapters
Reviews
Errata
Acknowledgments
Links on .NET
Paradoxal Press
Buy directly from Paradoxal Press at $33.99 (Save 43%)
Category: Programming
Level: Beginner to seasoned
900 pages
ISBN-10 097661322-0
ISBN-13 978-097661322-0
$59.99 USA
$79.99 CANADA
|
Listing 18-11 extracted from chapter Windows forms applications
Listing 18-10< > Listing 18-12
This listing can be compiled with the command line: csc.exe /target:exe Example_18_11.cs Errors: 0 Warnings: 0
Example_18_11.cs
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
public class Form1 : System.Windows.Forms.Form {
private Metafile m_Metafile;
private void OnClick1( object sender, System.EventArgs e ) {
using ( Graphics g = CreateGraphics() ) {
System.IntPtr hDC = g.GetHdc();
m_Metafile = new Metafile( hDC, EmfType.EmfPlusOnly );
using ( Graphics metafilegraphic = Graphics.FromImage(m_Metafile))
using ( Brush brush = new SolidBrush( Color.Black ) ) {
metafilegraphic.FillEllipse( brush, 10, 10, 50, 50 );
metafilegraphic.FillRectangle( brush, 5, 5, 10, 10 );
}
// You must always release the hDC or else
// an exception will be raised.
g.ReleaseHdc(hDC);
}
}
public void OnClick2( object sender, System.EventArgs e ) {
if( m_Metafile != null)
using ( Graphics g = CreateGraphics() ) {
g.DrawImage( m_Metafile, 10, 10 );
}
}
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.ComponentModel.Container components = null;
public Form1() {
InitializeComponent();
}
protected override void Dispose( bool disposing ) {
if (disposing) {
if (components != null) {
components.Dispose();
}
}
base.Dispose( disposing );
}
private void InitializeComponent() {
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
this.button1.Location = new System.Drawing.Point(208, 16);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "Click1";
this.button1.Click += new System.EventHandler( this.OnClick1 );
this.button2 = new System.Windows.Forms.Button();
this.button2.Location = new System.Drawing.Point(208, 48);
this.button2.Name = "button2";
this.button2.TabIndex = 0;
this.button2.Text = "Click2";
this.button2.Click += new System.EventHandler( this.OnClick2 );
this.AutoScaleDimensions = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.button1,this.button2});
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout( false );
}
[System.STAThread]
static void Main() {
System.Windows.Forms.Application.Run( new Form1() );
}
}
Copyright Patrick Smacchia 2006 2007
|