Xojo Conferences

Platforms to show: All Mac Windows Linux Cross-Platform

/MacCocoa/TextHeight calculation
Required plugins for this example: MBS MacBase Plugin, MBS MacCocoa Plugin, MBS Main Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCocoa/TextHeight calculation
This example is the version from Sat, 9th Oct 2015.
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

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

MBS Xojo PDF Plugins