1

Say I have a form application, and I draw a circle inside of it. Could I store a variable inside that circle object? Something like this?

Dim circle1.testVar As Integer = 1

Would that work, and is there a way to do this if it won't?

2
  • 2
    Only if the Circle class has a property testVar. And you would set it in this way: circle1.testVar = 1 Commented Nov 12, 2013 at 21:35
  • 1
    I'm guessing I can only use in built properties- .left etc. here? Commented Nov 12, 2013 at 21:43

1 Answer 1

2

No, you cannot dynamically add properties to a Control. you can use the existing Tag property of a control:

circle1.Tag = 1

Unfortunately Tag is of type Object so you're going to have to check for Nothing and/or cast the value when you retrieve it.

Sign up to request clarification or add additional context in comments.

6 Comments

That's a shame, thanks for your answer :) Could the tag property be defined as an array and thus store several pieces of information?
You can store an array, but Tag is still defined as an Object so you'll still need to cast when retrieving it.
Would that work through: circle1.Tag = {"a","b"} Console.WriteLine(circle1(0).ToString) ?
@niallmcfc You could assign it a Dictionary: circle1.Tag = new Dictionary<string, int>() for example to store multiple int values. To set a value: ((Dictionary<string, int>)circle1.Tag)["testVar"] = 1;
that would be:Console.WriteLine(circle1.Tag(0).ToString)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.