PictureBox.Tag treated as Integer

Posted on 2010-01-10
Medium Priority
Last Modified: 2012-05-08
Hello experts,

i have PictureBox on my form, as Tag I typed 1.

How can I retrieve the one value as integer?

I tried:

int i = (int)PictureBox.Tag;

but it didn't work.


Question by:panJacek
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 86

Accepted Solution

Mike Tomlinson earned 1880 total points
ID: 26277684
Things added to the Tag() property via the IDE are actually STRINGS so you need to parse it back to an integer:

            int i;
            if (int.TryParse((string)PictureBox.Tag, out i))
                // ...now do something with "i"...
                MessageBox.Show(i.ToString(), "i");
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 120 total points
ID: 26278576
Small distinction is that the Tag property is inherited from the System.Windows.Forms.Control class, and is an Object with a StringConverter as a TypeConverter.

[Bindable(true), SRCategory("CatData"), SRDescription("ControlTagDescr"), DefaultValue((string) null), Localizable(false), TypeConverter(typeof(StringConverter))]
public object Tag
        return this.Properties.GetObject(PropUserData);
        this.Properties.SetObject(PropUserData, value);

Open in new window


Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month7 days, 20 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question