Difference between revisions of "WebMenuItem.Tag"

From Xojo Documentation

m
 
Line 22: Line 22:
  
 
<rbcode>
 
<rbcode>
Dim file As New WebFile
+
Var file As New WebFile
 
file.MimeType = "text/plain"
 
file.MimeType = "text/plain"
 
file.ForceDownload = True // If False, the browser may try to display the file instead of download it
 
file.ForceDownload = True // If False, the browser may try to display the file instead of download it
Line 28: Line 28:
 
file.Data = "Hello, world!"
 
file.Data = "Hello, world!"
  
Dim base As New WebMenuItem
+
Var base As New WebMenuItem
 
   
 
   
Dim downloadMenu As New WebMenuItem("Download")
+
Var downloadMenu As New WebMenuItem("Download")
 
downloadMenu.Tag = file // The file to download
 
downloadMenu.Tag = file // The file to download
 
base.Append(downloadMenu)
 
base.Append(downloadMenu)
Line 42: Line 42:
 
<rbcode>
 
<rbcode>
 
If Item.Text = "Download" Then
 
If Item.Text = "Download" Then
   Dim file As WebFile = Item.Tag
+
   Var file As WebFile = Item.Tag
 
   ShowURL(file.URL)
 
   ShowURL(file.URL)
 
End If
 
End If
 
</rbcode>
 
</rbcode>

Latest revision as of 19:12, 2 August 2019

Property (As Variant )
aWebMenuItem.Tag = newVariantValue
or
VariantValue = aWebMenuItem.Tag

New in 2011r2

Supported for all project types and targets.

A hidden value associated with the menu item.

Notes

The tag is accessible via code when the user chooses the menu item but, unlike the Text property, is not displayed in the menu. It works like the RowTag property of a PopupMenu control.

The Tag is a variant so it can contain any value, including class references.

Example

This code displays a menu when you right-click on a Label. This code is in the Shown event handler of a WebLabel:

Var file As New WebFile
file.MimeType = "text/plain"
file.ForceDownload = True // If False, the browser may try to display the file instead of download it
file.FileName = "TextFile.txt"
file.Data = "Hello, world!"

Var base As New WebMenuItem

Var downloadMenu As New WebMenuItem("Download")
downloadMenu.Tag = file // The file to download
base.Append(downloadMenu)

Me.ContextualMenu = base


In the ContextualMenuAction event handler of the WebLabel, you can then use the tag to download the previously created file:

If Item.Text = "Download" Then
Var file As WebFile = Item.Tag
ShowURL(file.URL)
End If