Platforms to show: All Mac Windows Linux Cross-Platform
/MacCocoa/Printing/Printer Selection in Cocoa
Required plugins for this example: MBS MacBase Plugin, MBS Main Plugin, MBS MacCocoa Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCocoa/Printing/Printer Selection in Cocoa
This example is the version from Sun, 21th Feb 2015.
Project "Printer Selection in Cocoa.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control OpenPrinterButton Inherits PushButton
ControlInstance OpenPrinterButton Inherits PushButton
EventHandler Sub Action()
// Mac uses window title for print job
dim t as string = Title
title = CurrentMethodName
dim ps as new PrinterSetup
dim g as Graphics = OpenPrinter(ps)
if g<>Nil then
g.DrawString "Hello World", 50, 50
end if
// restore
Title = t
End EventHandler
End Control
Control OpenPrinterDialogButton Inherits PushButton
ControlInstance OpenPrinterDialogButton Inherits PushButton
EventHandler Sub Action()
// Mac uses window title for print job
dim t as string = Title
title = CurrentMethodName
dim ps as new PrinterSetup
dim g as Graphics = OpenPrinterDialog(ps)
if g<>Nil then
g.DrawString "Hello World", 50, 50
end if
// restore
Title = t
End EventHandler
End Control
Control List Inherits Listbox
ControlInstance List Inherits Listbox
EventHandler Sub DoubleClick()
dim PrintInfo as NSPrintInfoMBS = NSPrintInfoMBS.sharedPrintInfo
dim n as string = me.List(me.ListIndex)
dim p as NSPrinterMBS = NSPrinterMBS.printerWithName(n)
if p = nil then
MsgBox "Printer not found."
else
PrintInfo.printer = p
LoadList
end if
End EventHandler
End Control
Control Label1 Inherits Label
ControlInstance Label1 Inherits Label
End Control
Control Label2 Inherits Label
ControlInstance Label2 Inherits Label
End Control
Control Label3 Inherits Label
ControlInstance Label3 Inherits Label
End Control
EventHandler Sub Open()
LoadList
if not TargetCocoa then
MsgBox "This example is for Cocoa apps."
end if
End EventHandler
Sub LoadList()
dim printers() as string = NSPrinterMBS.printerNames
List.DeleteAllRows
dim PrintInfo as NSPrintInfoMBS = NSPrintInfoMBS.sharedPrintInfo
dim CurrentPrinter as string = PrintInfo.printer.name
for each printer as string in printers
List.AddRow printer
if CurrentPrinter = printer then
list.Cellbold(list.LastIndex,0) = true
end if
next
End Sub
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
The items on this page are in the following plugins: MBS MacCocoa Plugin.