WxPrintDialog-WxBasic

From WxWiki
Jump to navigation Jump to search

Work in progress

frame = new wxFrame( Null, -1, "wxFontDialog",
                     wxPoint(10, 10), wxSize(320, 200),
                     wxCAPTION | wxSYSTEM_MENU )
panel = new wxPanel( frame, -1 )
button = new wxButton( panel, -1, "print", wxPoint(120, 50) )

frame.Show(True)

bmp = new wxEmptyBitmap(0, 0) ' Declare the bitmap.
bmpDC = wxMemoryDC()          ' Create a device context for drawing on the bitmap.

' Load the bitmap from file.
bmp.LoadFile( "c:/documenti/immagine.bmp", wxBITMAP_TYPE_BMP )

' Allowed types for loading:
' wxBITMAP_TYPE_BMP
' wxBITMAP_TYPE_ICO
' wxBITMAP_TYPE_CUR
' wxBITMAP_TYPE_XBM
' wxBITMAP_TYPE_XPM
' wxBITMAP_TYPE_TIF
' wxBITMAP_TYPE_GIF
' wxBITMAP_TYPE_PNG
' wxBITMAP_TYPE_JPEG
' wxBITMAP_TYPE_PNM
' wxBITMAP_TYPE_PCX
' wxBITMAP_TYPE_PICT
' wxBITMAP_TYPE_ICON
' wxBITMAP_TYPE_MACCURSOR

' To draw onto your bitmap, you must select it into the memory device context.
bmpDC.SelectObject(bmp)

' Now you can draw your bitmap.
bmpDC.DrawLine(0, 0, 10, 20)

' Free the bitmap once you are done drawing.
bmpDC.SelectObject(wxNullBitmap)

' If you specify wxNO_3D, button will be "flat", looking like a normal bitmap:
' so you can draw bitmaps inside a panel (otherwise, you could only draw them
' in the main frame).
button1 = new wxBitmapButton( panel, -1, bmp, wxPoint(60, 100),
                              wxSize(-1, -1), wxNO_3D )

'You can also insert this bitmap inside a button.
button2 = new wxBitmapButton( panel, -1, bmp, wxPoint(10, 10), wxSize(-1, -1) )

' This SUB is neede to refresh drawing after window's redrawing.
Sub onPaint( event )
	dc = wxPaintDC( frame )
	dc.BeginDrawing()
	dc.Blit( 0, 0, 320, 200, bmpDC, 0, 0 )
	dc.EndDrawing()
End Sub

Connect( frame, -1, wxEVT_PAINT, "onPaint" )

Sub onPrint( event )
	pDialog = new wxPrintDialog(Nothing) ' Declare Printer Dialog.
	result = pDialog.ShowModal()         ' Store dialog result after showing it.
	pData = pDialog.GetPrintDialogData() ' Get resutlts from Printer Dialog.
	dc = pDialog.GetPrintDC()            ' Get DC data from Printer Dialog.

	dc.SetDeviceOrigin(400, 1000) ' Set the origin of the printed bitmap on the paper.
	dc.SetUserScale(10, 10)       ' Set printer scale: if (1, 1), each pixel will correspond to a dot
	                              ' on the printer; so, if your printer prints at 300 DPI, a 300 pixel
	                              ' wide image will be printed 1 inch wide.

	dc.StartDoc("printing...")            ' Begin new document to be printed.
	dc.StartPage()                        ' Begin new page to be printed.
	bmpDC.SelectObject(bmp)               ' "Enable" bitmap for "blitting".
	dc.Blit( 0, 0, 320, 200, bmpDC, 0, 0) ' Copy bitmap into printer DC.
	bmpDC.SelectObject(wxNullBitmap)      ' Free the bitmap.
	dc.EndPage()
	dc.EndDoc()
End Sub

Connect( button,  wxEVT_COMMAND_BUTTON_CLICKED, "onPrint" )

Back to WxBasic Tutorial