Results 1 to 3 of 3

Thread: [RESOLVED] Using an object stored as a Tag

  1. #1

    Thread Starter
    Fanatic Member Megalith's Avatar
    Join Date
    Oct 2006
    Location
    Secret location in the UK
    Posts
    879

    Resolved [RESOLVED] Using an object stored as a Tag

    Hi all,

    well heres another issue i can't find a solution to. Look at this example
    vb.net Code:
    1. Private Sub Button1_Click(sender As Object, _
    2.   e As EventArgs) Handles Button1.Click
    3.    Button1.Tag = LblPlacer.Margin
    4. End Sub
    5.  
    6. Private Sub Button2_Click(sender As Object, _
    7.   e As EventArgs) Handles Button2.Click
    8.     Button1.Margin = Button1.Tag ' this is wrong huh
    9. End Sub

    so how do i do this? what i am doing is as follows, when button1 is clicked the placer location is stored in button 1's tag property, this placer label is moved elsewhere by modifying its location in some manner. when i click button 2 then button 1 is moved to the location of the placer label when button1 was clicked.

    As for solutions this is just an exercise within these constraints, i know i could set a global thickness and use this but i wish for this example to use the Tag Property as although storing onto the tag is easy and examples abound, I have found no examples of what to do with an object in a tag. I'm guessing i need to use GetType for this?
    If debugging is the process of removing bugs, then programming must be the process of putting them in.

  2. #2
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: Using an object stored as a Tag

    You just need to cast it to the correct type:

    Code:
    Button1.Margin = DirectCast(Button1.Tag, Padding)
    It is safer to check the type however:

    Code:
    If TypeOf Button1.Tag Is Padding Then
    Button1.Margin = DirectCast(Button1.Tag, Padding)
    End If

  3. #3

    Thread Starter
    Fanatic Member Megalith's Avatar
    Join Date
    Oct 2006
    Location
    Secret location in the UK
    Posts
    879

    Re: Using an object stored as a Tag

    Quote Originally Posted by Grimfort View Post
    You just need to cast it to the correct type:

    Code:
    Button1.Margin = DirectCast(Button1.Tag, Padding)
    It is safer to check the type however:

    Code:
    If TypeOf Button1.Tag Is Padding Then
    Button1.Margin = DirectCast(Button1.Tag, Padding)
    End If
    Thanks Grimfort, I'll give that a go.
    If debugging is the process of removing bugs, then programming must be the process of putting them in.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width