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

/Cocoa/TextHeight calculation
Function: You find this example project in your Plugins Download as a Xojo (Real Studio) project file within the examples folder: /Cocoa/TextHeight calculation
Project "TextHeight calculation.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
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() // some graphics environment Dim NSGraphics as New NSGraphicsMBS() // the size of the label we have now dim size as NSSizeMBS = new NSSizeMBS(Label1.Width,Label1.Height) // and the text dim text as string = Label1.Text // make a NSFontMBS and pass it in the options dictionary dim font as NSFontMBS = NSFontMBS.fontWithName("Arial", 12) dim dic as new Dictionary dic.Value(NSAttributedStringMBS.NSFontAttributeName) = font // our options dim options as integer = NSGraphics.NSStringDrawingUsesLineFragmentOrigin + _ NSGraphics.NSStringDrawingUsesFontLeading + _ NSGraphics.NSStringDrawingUsesDeviceMetrics // and calculate the new rectangle Dim rect as NSRectMBS = NSGraphics.boundingRectWithSize(text, size, options, dic) // apply Label1.Height = rect.Height label1.Width = rect.Width End EventHandler
End Control
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 Xojo blog