Assign integer to this->Tag property.

https://msdn.microsoft.com/en-us/library/system.windows.forms.control.tag(v=vs.110).aspx

This website is saying that only text can be assigned to tag property.

Can i somehow change the datatype to integer instead of text?

Because i get 'error C2676' when i try this code:

 
this->Tag = this->Tag + 1;


error C2676: binary '+' : 'System::Object ^' does not define this operator or a conversion to a type acceptable to the predefined opera
Last edited on
You cannot change Tag to integer. However you may inherite from System::Object and add an integer member:
1
2
3
4
5
this->Tag = gcnew IntObj(...);

...

(IntObj^)(this->Tag)->Value += 1;
Witch way is better ?

1
2
3
4
5
this->Tag = gcnew IntObj(...);

...

(IntObj^)(this->Tag)->Value += 1;



OR


Convert::ToInt64(this->Tag) + 1;
Last edited on
The second one converts the value only. You cannot assign a value.

If you want to use Int64 you can directly use it:
1
2
3
4
5
this->Tag = gcnew Int64(...);

...

*((Int64^)(this->Tag)) += 1; // This should work / Not sure about that though 
I will have to write this->Tag = gcnew Int64(...); for every control i use.
for exapmple:
1
2
3
4
button->Tag = gcnew Int64(...);
button1->Tag = gcnew Int64(...);
label->Tag = gcnew Int64(...);
........



I could assign like this:
 
this->Tag = Convert::ToInt64(this->Tag) + 1;


Any other ways around?
Last edited on
Topic archived. No new replies allowed.