Tag Property

See Also1XPMYPG              ExamplePEXTAG>Low

Applies To

Form14TJ2LN, MDI form1ILMZQ7, check box9P3BU5, combo box1YZXFF6, command buttonXJSPC0, common dialog,1H1HYJI data control2E1FEX3, directory list boxO9U5A0, drive list box5WJO0PW, file list box1M6S8UX, frame1KX6ZP8, grid2VGT0PT, horizontal scroll bar1JSJOS7, image9A4FCA, label3MNIZ8D, lineTW530P, list boxG11UCK, menuBKDT1F, OLE control2HQDVVU, option buttonJYBO08, picture box31MYIWX, shape9JZFLA, text boxYPYZDG, timer3MVR08J, vertical scroll bar1JSJOS7.


Stores any extra data needed for your program.  Unlike other properties, the value of the Tag property is not used by Visual Basic; you can use this property to identify objects.


[form.][control.]Tag[ = expression ]


By default, the Tag property is set to an empty string ("").

You can use this property to assign an identification string to an object without affecting any of its other property settings or causing side effects.  The Tag property is useful when you need to check the identity of a control or MDI form that is passed as a variable to a procedure.


Tip     At the time you create a new instance of a form, assign a unique value to the Tag property.


Data Type


See Also


Name Property2016V9P


Programmer's Guide:

Chapter 3, "Creating and Using Controls"

Tag Property Example

The example displays a unique icon for each control being dragged.  To try this example, paste the code into the Declarations section of a form that contains three picture boxes.  Set the DragMode property for Picture1 and Picture2 to 1.  Then press F5. Use the mouse to drag Picure1 or Picture2 over Picture3 controls.

Sub Form_Load ()

   Picture1.Tag = "Pic1"

   Picture2.Tag = "Pic2"

End Sub


Sub Picture3_DragOver (Source As Control, X As Single, Y As Single, State As Integer)

   Const ENTER = 0, LEAVE = 1, OVER = 2

   If State = ENTER Then

      ' Select based on Tag. Name is not available at run time.

      Select Case Source.Tag

      Case "Pic1"

         ' Load icon for Picture1.

         Source.DragIcon = LoadPicture ("icons\arrows\point03.ico")

      Case "Pic2"

         ' Load icon for Picture 2.

         Source.DragIcon = LoadPicture ("icons\arrows\point04.ico")

      End Select

   ElseIf State = LEAVE Then

      ' When source is not over Picture3.

      Source.DragIcon = LoadPicture ()   'Unload icon.

   End If

End Sub