Platforms to show: All Mac Windows Linux Cross-Platform

/MacControls/Use Scrollview with ContainerControl


Required plugins for this example: MBS MacCocoa Plugin, MBS MacBase Plugin, MBS Main Plugin, MBS MacControls Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacControls/Use Scrollview with ContainerControl

This example is the version from Fri, 23th Feb 2023.

Project "Use Scrollview with ContainerControl.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control TestControl Inherits MyContainerControl
ControlInstance TestControl Inherits MyContainerControl
End Control
EventHandler Sub Open() Const ExtraSpace = 600 // get the window dim win as NSWindowMBS = self.NSWindowMBS // and content view dim contentView as NSViewMBS = win.contentView // now get the view for the container ContainerView = TestControl.NSViewMBS // and it's original size dim OutsideRect as NSRectMBS = ContainerView.frame // make it higher TestControl.Height = TestControl.Height + ExtraSpace // get new size dim InsideRect as NSRectMBS = ContainerView.frame // remove view from window ContainerView.removeFromSuperviewWithoutNeedingDisplay // build new scrollview ScrollView = New NSScrollViewMBS(OutsideRect.x, OutsideRect.y, OutsideRect.Width, OutsideRect.Height) // customize it ScrollView.hasVerticalScroller = true ScrollView.verticalScrollElasticity = ScrollView.NSScrollElasticityAllowed // use the container as document for the scrollview ScrollView.documentView = ContainerView // have it resize with window ScrollView.autoresizingMask = ContainerView.NSViewWidthSizable + ContainerView.NSViewHeightSizable // scroll to top dim newOrigin as new NSPointMBS(0, ExtraSpace) ScrollView.contentView.scrollToPoint newOrigin // put scrollview in window contentView.addSubview ScrollView End EventHandler
EventHandler Sub Resized() End EventHandler
EventHandler Sub Resizing() End EventHandler
Property ContainerView As NSViewMBS
Property ScrollView As NSScrollViewMBS
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
Class MyContainerControl Inherits ContainerControl
Control Rectangle1 Inherits Rectangle
ControlInstance Rectangle1 Inherits Rectangle
EventHandler Function MouseDown(X As Integer, Y As Integer) As Boolean // mouse events are relative to window, so be aware of that! label1.Text = str(x)+"/"+str(y) End EventHandler
End Control
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() MsgBox "Hello" End EventHandler
End Control
Control Label1 Inherits Label
ControlInstance Label1 Inherits Label
End Control
Control Label2 Inherits Label
ControlInstance Label2 Inherits Label
End Control
End Class
End Project

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


The biggest plugin in space...