[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:
Private Sub Button1_Click(sender As Object, _
e As EventArgs) Handles Button1.Click
Button1.Tag = LblPlacer.Margin
End Sub
Private Sub Button2_Click(sender As Object, _
e As EventArgs) Handles Button2.Click
Button1.Margin = Button1.Tag ' this is wrong huh
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?
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
Re: Using an object stored as a Tag
Quote:
Originally Posted by
Grimfort
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.