Used to create a toolbar in a window. The DesktopToolbar control is supported on all desktop platforms.
FileType As String
Type As String
button As DesktopToolbarItem
index As Integer
index As Integer
HitItem As DesktopMenuItem
item As DesktopToolbarItem
AllowAutoDeactivate As Boolean
Determines whether the control should be deactivated (on macOS) when the parent window is deactivated. The default is True.
AllowTabStop As Boolean
If True, the control is in the Tab Order and accepts the focus when the user tabs into it. The default is True. If False, the user cannot tab into it to give it the focus. However, the control can gain the focus by other means, such as the user's clicking on it or by setting the focus in code.
This example removes the control from the Tab Order:
Me.AllowTabStop = False
Enabled As Boolean
Determines if the control should be enabled when the owning window is opened.
A disabled control cannot be clicked and cannot receive the focus.
This example disables the control.
Me.Enabled = False
Handle As Ptr
Returns a handle to the control.
This property is read-only.
For interfacing with Mac APIs using Declares, DesktopControl.Handle returns NSViews (except for DesktopToolbar).
On Windows returns the HWND of the control.
On Linux it returns a GtkWidget.
The following gets a handle to the control.
Var p As Ptr = Me.Handle
Height As Integer
The height (in points) of the control.
This example sets the height of the control to 100:
Me.Height = 100
Name As String
The name of the control. Set the name of the control in the Inspector.
This property is read-only.
Parent As Object
Used to get and set the control's parent control or window.
If the control is on the window, the Parent will be the Window. If the control is on the container, the Parent will be the container. If the control is completed enclosed by another control, the Parent will be that control.
If the parent control is somehow in another window, an InvalidParentException will occur.
The following example sets the parent of the control to the window.
Me.Parent = Nil
Tooltip As String
Text of help message displayed as a Windows or Linux "tooltip" or macOS help tag.
The tip/tag is displayed when the user hovers the mouse cursor over the control.
This example adds a tooltip to a control:
Me.Tooltip = "Click to bark."
Transparent As Boolean
Determines whether the control is transparent on Windows. The default is False. Has no effect on macOS or Linux.
Transparent controls draw more slowly and use more memory in order to cache the background. Unless you absolutely require transparency, leave this set to False.
Visible As Boolean
Determines whether the control is visible when its owning window is opened. The default is True: the control is visible.
The following code makes the control invisible:
Me.Visible = False
Width As Integer
The width (in points) of the control.
The following example resizes the control:
Me.Width = 200
Window As DesktopWindow
The control's parent window.
This property is read-only.
This code gets the parent window's Title property.
AcceptFileDrop(FileType As String)
Permits documents of type FileType to be dropped on the control. FileType must be a file type that you defined in via the FileType class or the File Type Sets Editor.
This code in the Opening event makes it possible for the user to drop either a picture or a file that is a jpeg image. The File Type Sets editor was used to define the “image/jpeg” file type. It is one of the “Common File Types” that is available in the editor.
To restrict file drops to just folders (and not files), you can put this code in the DragEnter event:
If Not obj.FolderItem.IsFolder Then Return True
Permits pictures to be dropped on the control.
If a control should accept pictures in a drag and drop, then AcceptPictureDrop needs to be called prior to the drop. Typically, it is in the Opening event of the control itself. For example, the line:
in the Opening event of the control that will receive the dragged pictures is needed. When the picture is dropped, the DropObject event is called and this is where you will put your code to handle the drop.
If obj.PictureAvailable Then Me.Backdrop = obj.Picture End If
AcceptRawDataDrop(Type As String)
Permits data (of the Type specified) to be dropped on the control.
The following specfies a generic file type defined in the File Type Sets editor.
Permits text to be dropped on the control.
This line in the Opening event of a control that can accept dragged text.
AddButton(button As DesktopToolbarItem)
Adds the passed DesktopToolbarItem as the last element of the DesktopToolbar.
Inserts the passed DesktopToolbarItem in the position indicated by Index.
Returns the DesktopToolbarItem specified by Index.
Closes a control.
Closing a control permanently removes the control from memory, making it impossible to access. You can close both non-indexed controls and indexed controls. When you close an indexed control, the indexes for the remaining controls will shift downward so that the indexes start with zero and are consecutive.
The following code closes the control. When this is executed from a visible control, the control disappears from the window.
Count As Integer
The number of ToolItems in the DesktopToolbar.
Draws the contents of the control into the specified Graphics context. The parameters x and y are the coordinates of the top, left corner.
DrawInto will only work if the control is on a window or container.
This example draws the current control into the Graphics of a Picture and then displays it as the Backdrop of a Canvas:
Var p As New Picture(Me.Width, Me.Height) Me.DrawInto(p.Graphics, 0, 0) Canvas1.Backdrop = p
Redraws the portion specified of the contents of the control the next time the OS redraws the control or immediately if True is passed.
If you are calling this so frequently that you experience a slowdown in your code, pass True for the immediately parameter.
Calling this method causes the Render event to fire.
Refresh the entire area immediately:
Refresh a portion of the area the next time the OS redraws the control:
Me.Refresh(100, 150, 200, 300)
RemoveButtonAt(index As Integer)
Removes the passed item from the DesktopToolbar.
If applicable, sets the focus to the DesktopUIControl. KeyDown events are directed to the control.
If the control cannot get the focus on the platform on which the application is running, SetFocus does nothing. The SetFocus method of the DesktopWindow class or the ClearFocus method can be used to remove the focus from the control that currently has the focus, leaving no control with the focus.
On the Mac you need Full Keyboard Access turned on in System Preferences (Keyboard->Shortcuts) in order to manually set focus to non-text controls.
The following example in the Opening event sets the focus to the that control. If another control has the focus when this line is executed, then the user sees this control gets the focus.
The control is closing.
Fires when a contextual menuitem selectedItem was selected but the MenuItemSelected event and the MenuHandler for the DesktopMenuItem did not handle the menu selection.
This event gives you a chance to handle the menu selection by inspecting the menuitem's Text or Tag properties to see which item was selected. Use this in conjunction with ConstructContextualMenu if you have not specified the MenuItemSelected event or the Menu Handler for the items on the contextual menu. See the example of a contextual menu in the examples for the DesktopUIControl class.
Return True if this event has handled the item the user chose from the contextual menu. Returning False will cause the control's parent to execute its ContextualMenuAction event. This can be handy if you have the same contextual menu for several controls who share the same Parent (several on the same window for example). By returning False you can handle them all in a single event.
This simple event handler displays the value of the selected menu item.
If selectedItem <> Nil Then MessageBox(selectedItem.Text) Return True
The control has lost the focus.
On macOS, controls other than text fields and lists will accept and lose focus only if the full keyboard access option is enabled in System Preferences/Keyboard.
The control has received the focus and has a selection rectangle around it.
On macOS, controls other than text fields and lists will accept focus only if the full keyboard access option is enabled in System Preferences/Keyboard.
The mouse button was pressed inside the control's region at the location passed in to x, y.
This event fires repeatedly while the mouse button is being held down.
The coordinates x and y are local to the control, i.e. they represent the position of the mouse click relative to the upper-left corner or the control.
The Pressed event, if any, will not execute and the state of the object will not change.
You will receive the MouseUp event.
If you return False, the system handles the MouseDown so the MouseUp event handler do not get called.
The MouseDown event uses the DragItem constructor when the user drags the contents of the control. It is:
Var d As DragItem d = New DragItem(Self, Me.Left, Me.Top, Me.Width, Me.Height) d.Picture = Me.Image d.Drag // Allow the drag
The mouse button was pressed inside the control and moved (dragged) at the location local to the control passed in to x, y.
This event fires repeatedly while the mouse button is down regardless of whether or not the mouse coordinates are changing.
This event will not occur unless you return True in the MouseDown event.
The mouse button was released. Use the x and y parameters to determine if the mouse button was released within the control's boundaries.
This event will not occur unless you return True in the MouseDown event. The return value is ignored.
The parameters x and y are local coordinates, i.e. they represent the position of the mouse click relative to the upper-left corner or the control. Mouse clicks that are released to the left or above a control are negative.
The control is about to be displayed. Use this event to initialize a control.
The Opening event is called after the Constructor.
Be warned that initializing control property values using the Constructor instead of the Opening event may result in those property values being overwritten by what is set in the Inspector. For best results, use the Opening event for control initialization rather than the control Constructor.
If the control is supposed to handle drag and drop, you need to tell it which type of item it needs to be able to handle. The following example informs the control that pictures and files can be dropped on it. The type of the file it needs to support is specified via the File Types Editor.
Sub Opening() Me.AcceptPictureDrop Me.AcceptFileDrop("JPEG") End Sub
Pressed(item As DesktopToolbarItem)
The passed item was clicked.
A DesktopToolbar object contains all the buttons in a toolbar. You create the items in the toolbar with the DesktopToolbarButton class and add them to the toolbar with the AddButton or AddButtonAt methods. An item can be either a button or a divider. A button can work as either a pushbutton or a toggle button.
For best results, you should ensure that all your toolbar icons are the same size. Some platforms will size all icons to that of the icon on the first button in the toolbar.
You can only have a single toolbar on a Window.
Although DesktopToolbar inherits from DesktopUIControl, it has no mouse-related events. This is due to limitations of the operating system.
This example shows how to create a DesktopToolbar via code. It builds a small DesktopToolbar with Open and Save buttons. A DesktopToolbar object was added to a window. The pictures that are displayed by the two buttons were added to the project.
The window has the following properties:
SaveButton As DesktopToolbarButton OpenButton As DesktopToolbarButton
The following code is in the Opening event of the DesktopToolbar instance in the window.
SaveButton = New DesktopToolbarButton OpenButton = New DesktopToolbarButton SaveButton.Caption = "Save" // Caption appears below the Icon SaveButton.Name = "Save" SaveButton.icon = SaveButtonImage // image added to the project OpenButton.Caption = "Open" // Caption appears below the Icon OpenButton.Name = "Open" OpenButton.Icon = OpenButtonImage // image added to the project SaveButton.ButtonStyle = DesktopToolbarButton.ButtonStyles.PushButton OpenButton.ButtonStyle = DesktopToolbarButton.ButtonStyles.PushButton // add to the Toolbar Me.AddButton(OpenButton) Me.AddButton(SaveButton)
The following code is in the Pressed event of the DesktopToolbar in the window:
Sub Pressed(item As DesktopToolItem) Select Case item.Name Case "Open" MessageBox("You clicked the Open Button.") Case "Save" MessageBox("You clicked the Save Button.") End Select End Sub
Desktop projects on all supported operating systems.