Xojo Developer Conference
25/27th April 2018 in Denver.
MBS Xojo Conference
6/7th September 2018 in Munich, Germany.

Platforms to show: All Mac Windows Linux Cross-Platform

/CocoaControls/Label with Color
Function: You find this example project in your Plugins Download as a Xojo (Real Studio) project file within the examples folder: /CocoaControls/Label with Color
Project "Label with Color.rbp"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control Label1 Inherits Label
ControlInstance Label1 Inherits Label
End Control
EventHandler Sub Open() // get a font dim font as NSFontMBS = NSFontMBS.fontWithName("Lucida Grande", 18.0) // get some colors dim RedColor as NSColorMBS = NSColorMBS.colorWithDeviceRGB(1.0, 0.0, 0.0) dim GreenColor as NSColorMBS = NSColorMBS.colorWithDeviceRGB(0.0, 0.8, 0.0) dim BlueColor as NSColorMBS = NSColorMBS.colorWithDeviceRGB(0.0, 0.0, 1.0) // now make an attributed string dim a as NSAttributedStringMBS = NSAttributedStringMBS.attributedStringWithString("red green blue") dim t as NSMutableAttributedStringMBS = a.mutableCopy // set font for all characters t.addAttribute(NSAttributedStringMBS.NSFontAttributeName, font, new NSRangeMBS(0, t.length)) // set red as foreground color for the range with the text "red". Ranges start with zero! t.addAttribute(NSAttributedStringMBS.NSForegroundColorAttributeName, RedColor, new NSRangeMBS(0, 3)) // set green as foreground color for the range with the text "green" t.addAttribute(NSAttributedStringMBS.NSForegroundColorAttributeName, GreenColor, new NSRangeMBS(4, 5)) // set blue as foreground color for the range with the text "blue" t.addAttribute(NSAttributedStringMBS.NSForegroundColorAttributeName, BlueColor, new NSRangeMBS(10, 4)) // Now assign the label dim lbl as NSTextfieldMBS = label1.NSTextfieldMBS lbl.attributedStringValue = t End EventHandler
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
End Project

Feedback, Comments & Corrections




Links
MBS FileMaker tutorial videos