Xojo Conferences
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/Win/Print To Printer
Function:
Required plugins for this example: MBS Win Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Win/Print To Printer
This example is the version from Thu, 16th Dec 2015.
Project "Print To Printer.rbp"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control PopupPrinter Inherits PopupMenu
ControlInstance PopupPrinter Inherits PopupMenu
EventHandler Sub Open() // add printer names ot the popupmenu for each w as WindowsPrinterInfoMBS in WindowsPrinterInfoMBS.LocalPrinters me.addRow(w.PrinterName) me.RowTag(me.ListCount-1) = w next End EventHandler
End Control
Control Label1 Inherits Label
ControlInstance Label1 Inherits Label
End Control
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() // now we have nice setupstring dim ss as string = ps.SetupString 'MsgBox str(len(ss)) // parse it in device mode, to retain settings there dim d as WindowsDeviceModeMBS = WindowsDeviceModeMBS.FromSetupString(ss) if d = nil then // or start with a blank one d = new WindowsDeviceModeMBS end if // change printer if PopupPrinter.ListIndex >= 0 then dim w as WindowsPrinterInfoMBS = PopupPrinter.RowTag(PopupPrinter.ListIndex) // set device name d.DeviceName = w.PrinterName else MsgBox "No printer selected." Return end if // enable duplex 'd.Fields = BitwiseOr(d.Fields, d.DM_DUPLEX) 'd.Duplex = d.DMDUP_HORIZONTAL // get back as setup string dim da as string = d.SetupString if da = "" then MsgBox "failed to create setup string" Return end if // assign back ps.SetupString = da // and print something dim g as Graphics = OpenPrinter(ps) g.DrawString "Page on "+d.DeviceName, 50, 50 End EventHandler
End Control
EventHandler Sub Open() // xojo's class to store printer setup ps = new PrinterSetup End EventHandler
Property ps As PrinterSetup
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&Ablage"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Bearbeiten"
MenuItem EditUndo = "&Rückgängig"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "&Ausschneiden"
MenuItem EditCopy = "&Kopieren"
MenuItem EditPaste = "&Einfügen"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "&Alles auswählen"
End MenuBar
End Project

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS Win Plugin.




Links
MBS Xojo Chart Plugins