|
-
Mar 10th, 2011, 07:19 AM
#1
Thread Starter
Fanatic Member
[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?
If debugging is the process of removing bugs, then programming must be the process of putting them in.
-
Mar 10th, 2011, 07:33 AM
#2
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
-
Mar 10th, 2011, 07:36 AM
#3
Thread Starter
Fanatic Member
Re: Using an object stored as a Tag
 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.
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|