Where to put tooltip code?

Hello,
I put the below code in the MouseDown event of a button object.

DesktopApplication.ShowTooltip(txtPrefixDefi.Text,System.MouseX, System.MouseY + 20, True)

I get the error:

Static reference to instance method: call this on an instance of class DesktopApplication.

Where should I put this code? Thanks in advance.

Add ShowTooltip in the MouseEnter event.
Add HideTooltip in the MouseExit event

Hello,
I put the DesktopApplication.ShowTooltip code inside MouseEnter.
I’m still getting the same error. :cry:

app.showtooltip (str, X, Y)

Documentation ShowTooltip

1 Like

In other words “DesktopApplication” is the name of the class, but this method has to be called on an instance of the class. In this case, the App global variable is a reference to the instance:

App.ShowTooltip(txtPrefixDefi.Text,System.MouseX, System.MouseY + 20, True)


Say you have a class called FooBar with a method named DoStuff. If you try to call the DoStuff method on the name of the class itself, you’ll get an error:

FooBar.DoStuff() // Static reference to instance method

You have to create an instance of the class and use that:

Dim instance As New FooBar
instance.DoStuff()

Why are you using DesktopApplication.ShowTooltip?
Where did you see that code?

TimStreater:
I can see the text message. Thanks! (but what happened to the documentation advice to use DesktopApplication.ShowTooltip?)

@AlbertoD
https://documentation.xojo.com/versions/2022r2/api/deprecated/tooltip.html#tooltip

Yes, thank you. The page says:

This item was deprecated in version 2019r2. Please use DesktopApplication.ShowTooltip and DesktopApplication.HideTooltip as a replacement.

So, yeah, I used “DesktopApplication.ShowTooltip.” I still don’t know why that doesn’t work and what works is “App.ShowTooltip”. I’m a beginner; a beginner’s life is full of surprises.

If you follow the DesktopApplication.ShowTooltip link to the documentation you can see that the examples used say:

App.ShowTooltip(TextField1.Text, System.MouseX, System.MouseY + 20)

The nice thing about Xojo is that you can type DesktopApplication. after the dot you can press TAB to see what is available. You will not see ShowTooltip as an option. If you type App. then TAB you will see many options and one is ShowTooltip.

1 Like

Re class name and instance name, got it! And a very good tip. Thanks again.

@Resty_Cena

:+1:

1 Like