Notifications
Clear all

[Closed] changing dotnet Tooltip text

How can i change the tool tip text without creating hundreds of overlapping tooltips? In this example below, i would like the tooltip for each button to display how many times that button has individually been pressed.


try(destroyDialog ::rlButtonInfo)catch()
rollout rlButtonInfo "Buttons"
(
	local ToolTipObj = undefined

	dotnetcontrol uiOverridesA "System.Windows.Forms.Button" height:25 width:25 pos:[10,10]
	dotnetcontrol uiOverridesB "System.Windows.Forms.Button" height:25 width:25 pos:[40,10]
	dotnetcontrol uiOverridesC "System.Windows.Forms.Button" height:25 width:25 pos:[70,10]

	fn initializeButtons controls:#() =
	(
		for c in controls do
		(
			c.flatStyle = (dotNetClass "System.Windows.Forms.FlatStyle").Flat
			c.backcolor = (DotNetClass "System.Drawing.Color").fromARGB 50 100 240
			c.forecolor = (DotNetClass "System.Drawing.Color").fromARGB 20 70 210			
			c.TextAlign = (DotNetClass "System.Drawing.ContentAlignment").MiddleCenter
			c.text = "•"

			ToolTipObj = dotnetobject "System.Windows.Forms.ToolTip" 
			ToolTipObj.Active = True
			ToolTipObj.ToolTipIcon = (dotnetclass "System.Windows.Forms.ToolTipIcon").info
			ToolTipObj.isballoon = True 
			ToolTipObj.ShowAlways = true
			ToolTipObj.ToolTipTitle = "Settings"
			ToolTipObj.SetToolTip c "none" 
		)
	)

	fn UpdateToolTips =
	(
		local controls = #(uiOverridesA, uiOverridesB, uiOverridesC)
		
		for c in controls do
		(
			local infoString = (random 10 1000) as string
			
			--SET AS TOOLTIP
			--ToolTipObj.SetToolTip ctrl infoString 
		)
	)
		
	-- BUTTON ACTIONS
	on uiOverridesA Click e do UpdateToolTips()	
	on uiOverridesB Click e do UpdateToolTips()	
	on uiOverridesC Click e do UpdateToolTips()
	
	on rlButtonInfo open do
	(
		initializeButtons controls:#(uiOverridesA, uiOverridesB, uiOverridesC)
	)
)
createdialog rlButtonInfo 220 75 style:#(#style_toolwindow, #style_sysmenu) 

10 Replies

Try creating only one instance of the ToolTip object (instead of one instance for each control), and then use SetToolTip().

 lo1

And also keep a reference to ToolTipObj as a rollout local so it doesn’t get GCed away.

5 Replies
(@polytools3d)
Joined: 11 months ago

Posts: 0

Yes, that’s the idea of creating just one instance. Basically you need to move the follosing line outside the function and make it a rollout local:

ToolTipObj = dotnetobject "System.Windows.Forms.ToolTip"

You could also make the icon a local variable:

ToolTipObj.ToolTipIcon = (dotnetclass "System.Windows.Forms.ToolTipIcon").info
 lo1
(@lo1)
Joined: 11 months ago

Posts: 0

Why do that? It’s an enumeration

(@polytools3d)
Joined: 11 months ago

Posts: 0

Why would you create one instance for each control?

 lo1
(@lo1)
Joined: 11 months ago

Posts: 0

(dotnetclass “System.Windows.Forms.ToolTipIcon”).info is an enum, not an object being created.
Or maybe we’ve misunderstood each other.

(@polytools3d)
Joined: 11 months ago

Posts: 0

I provably used the word “instance” in a wrong way. Perhaps “variable” should be it. I mean this:

(
      	local tooltip = dotnetobject "System.Windows.Forms.ToolTip" 
      
      	st = timestamp(); sh = heapfree
      	for j = 1 to 1000 do tooltip.ToolTipIcon = (dotnetclass "System.Windows.Forms.ToolTipIcon").info
      	format "time:% ram:% 
" (timestamp()-st) (sh-heapfree)
      
      	st = timestamp(); sh = heapfree
      	icon = (dotnetclass "System.Windows.Forms.ToolTipIcon").info
      	for j = 1 to 1000 do tooltip.ToolTipIcon = icon
      	format "time:% ram:% 
" (timestamp()-st) (sh-heapfree)
      )

thanks Rotem!


try(destroyDialog ::rlButtonInfo)catch()
rollout rlButtonInfo "Buttons"
(
	local ToolTipObj = undefined
	local countClicks = #(0,0,0)

	dotnetcontrol uiOverridesA "System.Windows.Forms.Button" height:25 width:25 pos:[10,10]
	dotnetcontrol uiOverridesB "System.Windows.Forms.Button" height:25 width:25 pos:[40,10]
	dotnetcontrol uiOverridesC "System.Windows.Forms.Button" height:25 width:25 pos:[70,10]

	fn initializeButtons controls:#() =
	(
		ToolTipObj = dotnetobject "System.Windows.Forms.ToolTip" 
		ToolTipObj.Active = True
		ToolTipObj.ToolTipIcon = (dotnetclass "System.Windows.Forms.ToolTipIcon").info
		ToolTipObj.isballoon = True 
		ToolTipObj.ShowAlways = true
		ToolTipObj.ToolTipTitle = "Settings"
--		ToolTipObj.SetToolTip c "none" 

		for ctrl in controls do
		(
			ctrl.flatStyle = (dotNetClass "System.Windows.Forms.FlatStyle").Flat
			ctrl.backcolor = (DotNetClass "System.Drawing.Color").fromARGB 50 100 240
			ctrl.forecolor = (DotNetClass "System.Drawing.Color").fromARGB 20 70 210			
			ctrl.TextAlign = (DotNetClass "System.Drawing.ContentAlignment").MiddleCenter
			ctrl.text = "•"
			ctrl.Tag = 0
			TooltipObj.SetTooltip ctrl (ctrl.Tag as string)  
		)
	)

	fn UpdateToolTips ctrl =
	(
		ctrl.Tag +=1
		TooltipObj.SetTooltip ctrl (ctrl.Tag as string)  
	)

	-- BUTTON ACTIONS
	on uiOverridesA Click e do UpdateToolTips uiOverridesA
	on uiOverridesB Click e do UpdateToolTips uiOverridesB
	on uiOverridesC Click e do UpdateToolTips uiOverridesC
		
	on rlButtonInfo open do
	(
		initializeButtons controls:#(uiOverridesA, uiOverridesB, uiOverridesC)
	)
)
createdialog rlButtonInfo 220 75 style:#(#style_toolwindow, #style_sysmenu) 

1 Reply
(@polytools3d)
Joined: 11 months ago

Posts: 0
     You are very welcome John! I am always happy to help too.

on rollout i have dotnet textbox and a tooltip which i plan to show manually after user input
What second arg should i pass to .Show() method to make it work?

.Show <System.String>text <System.Windows.Forms.IWin32Window>window

looks like it was that simple

myrollout.tooltip.show “we are opened” myrollout.textbox