I am new here

I didn’t manage to make the load external fonts work because some examples I found are old and maybe incompatible with this version of Xojo. I will return to this problem later on.
I tried to play with TOOLBARS.
I inserted 1 Toolbar with 1 menu(toolbar) item but the tool bar is not present in the window.
Do the selected item from the contents of the project tree matters when you are inserting a toolbar?
Just selecting the main project window and inserting a Toolbar it adds the toolbar in the project tree at the bottom.
The toolbar is not visible on the window BUT if I will have the window selected and I drag the Toolbar1 from the bottom of the Project Tree inside the window, then it is placed at the bottom of the window views side by side with my timer.
After that, it creates and a second Toolbar with name Toolbar11. With this way I can see the toolbar on the main window.
toolbar11
I played a little and I understood that there are 2 toolbars.
The first tool bar needs to be placed on the window that will be visible and the second will contain the menus and the icons and the one that will be placed on the window that will be visible will need to have the setting: Super: Toolbar0 (something that will tell to Xojo this Toolbar points to the other Toolbar that contains the menus and the icons. I think).
Initially the toolbar with name Toolbar11 had the setting Super: Toolbar1 but I renamed the toolbar at the bottom of the project tree as toolbar0 and the toolbar that is inside the main window I renamed it as Toolbar1

I am already see this video and I followed the instructions of this video and all of these happened I wrote above.
Also I have and a new error when I added icons in the toolbar (also there is no way to remove an item from the toolbar, you need to delete it whole).

Ok, let’ say I will delete the whole Toolbar and I will add it again. I am doing the same this guy does.
I have selected my main window. I chosen insert from the menu upper left the blue button.

After I added 2 buttons in the toolbar I have these errors. (I deleted all the previous bars I do not have any left over from the previous edit).

  • Toolbar1.newButton (property name)
    There is more than one method with this name but this does not match any of the available signatures.
    Name

  • Toolbar1.newButton (property name)
    Type mismatch error. Expected class Picture, but got Int32
    Name

  • Toolbar1.loadButton (property name)
    There is more than one method with this name but this does not match any of the available signatures.
    Name

  • Toolbar1.loadButton (property name)
    Type mismatch error. Expected class Picture, but got Int32
    Name

1 Like

One Toolbar is the Class, the design. Once applied to the window it’s called an instance of the Toolbar.
You just need to edit that Toolbar Class and it reflects where it was applied. If you set such icon to none in the class it vanishes. If you click on its label and press del (or the current del key set in the option as control+del), it gets deleted.

Well, If I will remove the icon from the button of the toolbar the error disappears. But I discovered what was the error.
I was named the icon as “New_Adventure” (The graphic of the image)
And the name of the first Button in the Toolbar “New_Adventure” so the language seen the name “New_Adventure” was used twice. Maybe this is a bug. Because the name of the graphic can be anything but the Xojo conflicts the names with the variables. I will need to be careful. Of course I didn’t know the names you put everywhere in the menus or in the window or in some gadget can be conflict with another one if it is the same.

This worked (But it misses the ability to able to remove some button if you have added more or made an error, you have to delete the whole Toolbar if you want to fix something).

I have new question.
All the menus on my MenuBar are disabled. How do I will enable them? Or Enable some of them.
I found it. You call its name with a property enabled = True.
For example my menu item name is “new_Adventure” then I add the code at the beginning of the program in the opening even of the main window

new_Adventure.Enabled = True
save_Adventure.Enabled = False

And each menu gets enabled or disabled. But It didn’t work. :frowning:

You asked how to use a custom CURSor…

Here’s some code:



Dim Clip As New Clipboard
Dim Curs_Pict As New Picture(40,40)

If Clip.PictureAvailable Then
  Curs_Pict = Clip.Picture
  Clip.Close
  Dim thisMouse As New MouseCursor(Curs_Pict, 0, 0)
  
  Me.MouseCursor = thisMouse
End If

Remove the Clipboard part and load your image from a file on disk.

Warning: use a small cursor image, not a 640 x 480 image file as I do the first time by mistake. No crash, but surprising to see a so large cursor…

Enjoy

1 Like

Can I use an image that is stored inside the graphics?
Removing the clipboard part and load and image from the disk, I do not know which command load images.

Either drag the image into the project and refer to it by name.

Var thisMouse As New MouseCursor(MyCursor, 0, 0) ' Assuming an picture dragged into the IDE called MyCursor
Me.MouseCursor = thisMouse

Or if it is stored on disk:

Var oFile as FolderItem
Var oPicture as Picture

oFile = SpecialFolder.Desktop.Child( "MyCursor.png" ) ' Or any other location you want.
oPicture = Picture.Open ( oFile ) ' Loads the image on disk into a Picture object.
Var thisMouse As New MouseCursor(oPicture, 0, 0)
Me.MouseCursor = thisMouse

It worked thank you very very much.

I do not tested that under Linux nor Windows, but I am quiet sure it will works…

When I am opening a new window the cursor returns to arrow again. Do I need to set the cursor each time I am opening a new window?

It depends on the scope in which you’ve set the mouse cursor. You can set it on the individual control level if you like, the window level (which I’m assuming is where you’ve put me.), or the App level. Setting it on the App level is probably what you want.

1 Like

And how do I am doing this? :blush:

For example if I would like to have a global variable that the whole program in any window can see it.

By changing which object you’re setting the MouseCursor property on:
https://documentation.xojo.com/api/deprecated/application.html#application-mousecursor

Perfect.
I changed the “me” to “app” I added it at opening event of the main window.

App.MouseCursor = thisMouse

And the cursor now is the same everywhere.
Thank you very much.

Now I have new question about how to enable and disable menu items for Normal Menus and ToolBars.

MenuItems can be set to AutoEnabled, in which case they’re on automatically. If you want more control then set AutoEnabled to false and then add a MenuBarSelected to your app or window. In that you can set Enabled=true on MenuItems you want using any logic you require.

Put the event on App if you want items to be enabled / disabled no matter which window is in the foreground.

Put the event on a Window if you want the logic to depend on that class of Window being the frontmost.

You can obviously do both at the same time.

For example if you had a document editing application you would want to AutoActivate the New and Open items and Quit. You would only want Save enabled if the document was the frontmost window.

Toolbars are another issue. They are available and visible all the time so you need to deal with activating / deactivating them when your application changes state. There is no event to trigger enabling or disabling.

1 Like

Strange the AutoEnabled is set to “on” and all the menu items of my normal menus are disabled except the Exit Menu.
What you mean when you say to add a MenuBarSelected? I have added a normal main menu bar and the default name that took was “MainMenuBar”

I tried to add this:

App.MenuBar.Enabled = true
new_Adventure.Enabled = false

The MenuBar is the main window menu bar
The new_Adventure.Enabled is a menu item.
But it wasn’t enabled.

You have to have implemented the MenuHandler for that menu in either the application or the current Window. That’s what AutoEnabled means. It means you’ve implemented the MenuHandler so it can be used.

You can’t have App.MenuBar the application doesn’t have a menubar. In App.MenuBarSelected event:

Sorry, I missed the word event. Select you App object and choose Add Event, select MenuBarSelected.

new_Adventure.Enabled = false

will disable that MenuItem no matter which window is shown.

For a Window you can do the same. Click the window and add an Event MenuBarSelected, in there you can enable / disable any MenuItem by name.

It might be better to start new topics when you want to ask a new question. IE one for cursors, one for menus / toolbars etc.

2 Likes