Notifications
Clear all

[Closed] Tooltips for DotNet Buttons

I don’t see a “Tooltip” property for DN buttons. Any ideas on the best way to add them?

My first thought is to just add one of the Mouse events to check if the cursor is over the button and print some text at the bottom of my UI. But it would be nice to have a more Max-like tooltip pop up.

13 Replies

A tooltip isn’t a property, but a separately instantiated object of type System.Windows.Forms.ToolTip. You associate it with the control using one of ToolTip’s methods:


   dnForm1 = dotnetobject "Form"
   dnButton1  = dotnetobject "Button"
   dnToolTip = dotnetobject "ToolTip"
   dnButton1.text =  "Do Nothing"
   
    
   dnToolTip.AutoPopDelay = 5000
   dnToolTip.InitialDelay = 300
   dnToolTip.ReshowDelay = 300
   dnToolTip.ShowAlways = true
   
   dnToolTip.SetToolTip dnForm1 "I'm a Form"		 
   dnToolTip.SetToolTip dnButton1  "I'm a Button"  
   
   
   dnForm1.controls.add  dnButton1
   dnForm1.show()
  
            

hi james, hope you’re well.

rollout DotNetTest ""
 (
     
 dotnetcontrol mbutton "System.Windows.Forms.Button" height:60 width:60 pos:[5,5]
 dotnetcontrol mbutton2 "System.Windows.Forms.Button" height:60 width:60 pos:[75,5]
         
     on dotnettest open do
     (
     ToolTipObj = dotnetobject "System.Windows.Forms.ToolTip"
     ToolTipObj.SetToolTip mbutton "Funky cold medina"    
     ToolTipObj.Active = True
     ToolTipObj.tooltipicon = (dotnetclass "System.Windows.Forms.ToolTipIcon").warning
         -- other types of tooltip icon are 
         --.Error
         -- .info
         -- .none
         
     ToolTipObj2= dotnetobject "System.Windows.Forms.ToolTip"
     ToolTipObj2.SetToolTip mbutton2 "Get out of my dreams, get into my car"    
     ToolTipObj2.Active = True    
     ToolTipObj2.isballoon = True            
     )
 )
 createdialog dotnettest 145 75 style:#(#style_toolwindow, #style_sysmenu) 

one method of implementing this could be to call a tooltip function in mouseover handler – then you could pass the sender to it and change the tooltip.settooltip depending on which one it is.

edit – hey drdubosc you’re too fast!

Bells! Whistles! … they take time …

heh heh

just for completeness, this is the other method, probably better as you just use the one tooltip instance. it also checks for button focus, which might or might not be what you want.

on an mxs dialog you have to emulate the sender functionality of a dotnet form. If you use a dotnet form however, you can use addeventhandler to bind the function to multiple controls at the rollout creation.


 
 rollout DotNetTest ""
 (	
 	fn tooltiphandler control =
 	(
 		ToolTipObj = dotnetobject "System.Windows.Forms.ToolTip"
 		
 		if control.focused == true do
 		(
 			case control of
 			(
 			(dotnettest.mbutton):(ToolTipObj.SetToolTip dotnettest.mbutton "Funky cold medina")
 			(dotnettest.mbutton2):(ToolTipObj.SetToolTip dotnettest.mbutton2 "Get out of my dreams, get into my car")	
 			)
 			ToolTipObj.Active = True
 		)
 		
 	)
 		
 	dotnetcontrol mbutton "System.Windows.Forms.Button" height:60 width:60 pos:[5,5]
 	dotnetcontrol mbutton2 "System.Windows.Forms.Button" height:60 width:60 pos:[75,5]
 	on mbutton mouseenter do tooltiphandler mbutton
 	on mbutton2 mouseenter do tooltiphandler mbutton2
 
 )
 createdialog dotnettest 145 75 style:#(#style_toolwindow, #style_sysmenu) 

Hi, Pete,

Got a question for you. ( I'm OK-ish at .net, but no good at MXS style). This code seems more in the spirit of the System.Windows.Forms.ToolTip object, to me, than your example, because you really shouldn't have to call SetToolTip on every mouseenter event. It's already registered that lot behind your back.
rollout dotnettest ""
   (	
     dotnetcontrol mbutton "System.Windows.Forms.Button" height:60 width:60 pos:[5,5]
     dotnetcontrol mbutton2 "System.Windows.Forms.Button" height:60 width:60 pos:[75,5]
     on dotnettest open do (
   	ToolTipObj = dotnetobject "System.Windows.Forms.ToolTip"
   	ToolTipObj.SetToolTip dotnettest.mbutton "Funky cold medina"
   	ToolTipObj.SetToolTip dotnettest.mbutton2 "Get out of my dreams, get into my car"
     ) 
   )
   createdialog dotnettest 145 75 style:#(#style_toolwindow, #style_sysmenu)
   
But now I've polluted the global namespace with 'ToolTipObj'. 
In .net I'd tuck it away into the Form-derived form. How do I hide it away in MXS? Its not a control I can pop into the rollout.

You are absoultely right. I did employ a needless call of settooltip – my example was adapted from some vb code i had written that dynamically changed the tooltip display depending on what was selected on a dynamically generated UI (so no absolute button assignments to go on!)

Do you mean because tooltip is a component rather than a control? (a bit like rightclick menus, background workers etc…) isn’t it not just local to the rollout?

No… once ToolTipObj is created in on dotnettest open, it’s global. I’d like to be able to declare it inside the rollout, but you can only do that with <rollout control>’s. This maybe is a bit off-topic. I’m really asking how to add properties to rollouts, or how to jam the whole lot into a struct, or something like that.

my bad! i’d typed it wrong in the listener! you could put the whole thing into a struct – i do this will all my rollouts, you just whack them into a ui function- no global value for tooltipobj now.


global dnbits 

struct DotNetBits 
(
	ToolTipObj = dotnetobject "System.Windows.Forms.ToolTip",

	fn ui =
	(

	rollout dotnettest ""
	   (	
		 dotnetcontrol mbutton "System.Windows.Forms.Button" height:60 width:60 pos:[5,5]
		 dotnetcontrol mbutton2 "System.Windows.Forms.Button" height:60 width:60 pos:[75,5]
		 on dotnettest open do
			(		
			ToolTipObj.SetToolTip dotnettest.mbutton "Funky cold medina"
			ToolTipObj.SetToolTip dotnettest.mbutton2 "Get out of my dreams, get into my car"
			) 
	   )
	   createdialog dotnettest 145 75 style:#(#style_toolwindow, #style_sysmenu)
	)
)

dnbits = dotnetbits()
dnbits.ui()

ToolTipObj

or use a rollout-local variable:


rollout dotnettest "" (	
	local ToolTipObj
	dotnetcontrol mbutton "System.Windows.Forms.Button" height:60 width:60 pos:[5,5]
	dotnetcontrol mbutton2 "System.Windows.Forms.Button" height:60 width:60 pos:[75,5]
	on dotnettest open do (
		ToolTipObj = dotnetobject "System.Windows.Forms.ToolTip"
		ToolTipObj.SetToolTip dotnettest.mbutton "Funky cold medina"
		ToolTipObj.SetToolTip dotnettest.mbutton2 "Get out of my dreams, get into my car"
	) 
)
Rollout:dotnettest
createdialog dotnettest 145 75 style:#(#style_toolwindow, #style_sysmenu)
true
ToolTipObj
undefined

Structs can be cleaner, especially if there’s a lot of functionality shared between different code / rollouts / scripts.

Page 1 / 2