Public partial class frmPrint: DevExpress. XtraEditors. XtraForm
{
Bitmap myPic;
Bool landscape = false;
// Constructor
Public frmPrint (string mypic)
{
InitializeComponent ();
MyPic = new Bitmap (mypic );
This. pictureEdit1.Image = myPic;
}
// Plot when printing
Private void printdocumentemediprintpage (object sender, System. Drawing. Printing. PrintPageEventArgs e)
{
E. Graphics. DrawImage (myPic, 0, 0 );
}
// Close
Private void toolStripButton2_Click (object sender, EventArgs e)
{
This. Close ();
}
// Print
Private void toolstripbutton#click (object sender, EventArgs e)
{
PrintDialog MyPrintDg = new PrintDialog ();
MyPrintDg. Document = printDocument1;
If (landscape)
Printdocument1.defapagpagesettings. Landscape = true;
Else
Printdocument1.defapagpagesettings. Landscape = false;
If (MyPrintDg. ShowDialog () = DialogResult. OK)
{
Try
{
PrintDocument1.Print ();
}
Catch
{// Stop printing
PrintDocument1.PrintController. OnEndPrint (printDocument1, new System. Drawing. Printing. PrintEventArgs ());
}
}
}
// Whether to print the horizontal panel
Private void toolstripcheckbox#checkedchanged (object sender, EventArgs e)
{
Landscape =! Landscape;
}
// The form will be closed soon
Private void frmPrint_FormClosing (object sender, FormClosingEventArgs e)
{
PictureEdit1.Dispose ();
MyPic. Dispose ();
Directory. SetCurrentDirectory (Application. StartupPath );
If (Directory. Exists (Application. StartupPath + "\ tmpbmp "))
{
Directory. Delete (Application. StartupPath + "\ tmpbmp", true );
}
E. Cancel = false;
}
}