The attached Visual COBOL project contains a .NET managed code Windows Forms application that demonstrates how to allow a user to click on a button and automatically display a Print Preview Dialog or to send the image of the current form to the default printer for printing.
$set ilusing"System.Text"
$set ilusing"System.Drawing.Printing"
$set ilusing"System.Windows.Forms"
class-id screenprintvc.Form1 is
partial inherits type System.Windows.Forms.Form.
working-storage section.
01 PrintDoc1 type PrintDocument value new PrintDocument.
01 PPDlg1 type PrintPreviewDialog value new PrintPreviewDialog.
method-id NEW.
procedure division.
invoke self::InitializeComponent
set PPDlg1::Document to PrintDoc1
set PrintDoc1::OriginAtMargins to true
invoke PrintDoc1::add_PrintPage(new System.Drawing.Printing.PrintPageEventHandler (self::pDoc_PrintPage))
goback.
end method.
method-id pDoc_PrintPage private.
local-storage section.
01 bmp type Bitmap.
procedure division using by value sender as object, e as type PrintPageEventArgs.
set bmp to new type Bitmap(self::Width, self::Height)
*>Takes the Snap of the Exact WindowForm size as Bitmap image
invoke self::DrawToBitmap(bmp, new type Rectangle(0, 0, bmp::Width, bmp::Height))
invoke e::Graphics::DrawImage(bmp, 0, 0)
end method.
method-id btn_PrintPreview_Click final private.
procedure division using by value sender as object e as type System.EventArgs.
invoke PPDlg1::ShowDialog
end method.
method-id btn_PrintPage_Click final private.
procedure division using by value sender as object e as type System.EventArgs.
invoke PrintDoc1::Print
end method.
end class.
#COBOL
#HowTo-BestPractice
#VisualCOBOL
#VisualStudio
#.net