12 Replies - 1491 Views - Last Post: 10 March 2011 - 08:00 AM Rate Topic: -----

#1 mfaheemriaz   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 23-September 08

What is [controlName].Tag?

Posted 09 March 2011 - 11:59 AM

hi

i am learning C#, please tell me what is it [textBox1.Tag]
in other words what does it do? or what are its properties?

This post has been edited by mfaheemriaz: 09 March 2011 - 12:00 PM

Is This A Good Question/Topic? 0
  • +

Replies To: What is [controlName].Tag?

#2 Sergio Tapia   User is offline

  • D.I.C Lover
  • member icon

Reputation: 1258
  • View blog
  • Posts: 4,168
  • Joined: 27-January 10

Re: What is [controlName].Tag?

Posted 09 March 2011 - 12:07 PM

http://msdn.microsof...ontrol.tag.aspx
Was This Post Helpful? 0
  • +
  • -

#3 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6259
  • View blog
  • Posts: 24,028
  • Joined: 23-August 08

Re: What is [controlName].Tag?

Posted 09 March 2011 - 12:20 PM

Please do NOT use stupid titles like "C# Helppp". We KNOW you need C# help, or you WOULDN'T have posted in the C# forum!!! Use a descriptive title like that to which I've Sergio Tapia renamed yours.

This post has been edited by insertAlias: 09 March 2011 - 12:45 PM

Was This Post Helpful? 0
  • +
  • -

#4 Curtis Rutland   User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 5106
  • View blog
  • Posts: 9,283
  • Joined: 08-June 10

Re: What is [controlName].Tag?

Posted 09 March 2011 - 12:20 PM

We already know you need C# help, you came to the C# Help Forum. Please use more descriptive titles. I've fixed it for you this time.

Edit: Great minds think alike, Jack. I must have edited it a few seconds after you.

As Sergio's link points out, it's basically just a drop box where you can put whatever you want in it. It's totally up to you what you want to go there.

This post has been edited by insertAlias: 09 March 2011 - 12:21 PM

Was This Post Helpful? 0
  • +
  • -

#5 mfaheemriaz   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 23-September 08

Re: What is [controlName].Tag?

Posted 09 March 2011 - 12:44 PM

as i told u i am new here and new to C#, please be polite i was almost going to cry, the way u said, i make that topic so i can find it easily and can also post my problems here....

anyways thanks
Was This Post Helpful? 0
  • +
  • -

#6 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6537
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: What is [controlName].Tag?

Posted 09 March 2011 - 12:46 PM

Learning to use IntelliSense is going to play a vital role in learning C#.
As you type Visual Studio's IntelliSense feature gives you targeted information about the code you are trying to enter.
Attached Image
In your example about a textbox you can see the description for .Text tells you it is a property of the 'string' type with a description of how to use it "Gets or sets the current text in the TextBox"

For the .Tag property it tells you it is a property of type 'object' from the namespace "System.Windows.Forms.Control.Tag" and to use it: "Gets or sets the object that contains data about the control."

In other words a .Tag can contain any other kind of object. That makes it a very handy property in my book, because it can contain just about anything else.

You could have an treenode, then set it's .Tag property to the object to be used when someone clicks on that node for example.

For a textbox you could set the .Tag to a PersonObj object, override the ToString() method to supply just the name, yet the rest of the object has all their details like age and hair color.

I am going to guess that you are trying to teach yourself C# without much guidance, a decent book or without knowing where to look. Sometimes just knowing where to look can make all the difference. Google is your friend.
Search with either "C#" or "MSDN" as the first word: "MSDN Picturebox", "C# Custom Events", "MSDN timer" etc.

But honestly, just typing away and seeing what pops up in Intellisense is going to make your self-education take 20 years. You can learn by trying to reverse engineer the language through banging on the keyboard experimentation - or you can learn by doing the tutorials and following a good "How to learn C#" book.

May I suggest picking up a basic C# introductory book? There are so many great "How do I build my first application" tutorials on the web... There are dozens of "Learn C# in 21 days", "My first C# program" books at your local book seller or even public library.

C# resources. Start here
Intro to C# online tutorial then here...
C# control structures then here.
MSDN video on OOP principals, making classes, constructors, accessors and method overloading

The tutorials below walk through making an application including inheritance, custom events and custom controls.
Quick and easy custom events
Bulding an application - Part 1
Building an application - Part 2
Debugging tutorial
Working with environmental variables


Build a Program Now! in Visual C# by Microsoft Press, ISBN 0-7356-2542-5
is a terrific book that has you build a Windows Forms application, a WPF app, a database application, your own web browser.

C# Cookbooks
Are a great place to get good code, broken down by need, written by coding professionals. You can use the code as-is, but take the time to actually study it. These professionals write in a certain style for a reason developed by years of experience and heartache.

Microsoft Visual Studio Tips, 251 ways to improve your productivity, Microsoft press, ISBN 0-7356-2640-5
Has many, many great, real-world tips that I use all the time.

Writing a text file is always one of the first things people want to do, in order to store data like high-scores, preferences and so on
Writing a text file tutorial.

These are just good every-day references to put in your bookmarks.
MSDN C# Developers Center with tutorials
Welcome to Visual Studio

Have you seen the 500+ MSDN Code Samples? They spent a lot of time creating samples and demos. It seems a shame to not use them.

This post has been edited by tlhIn`toq: 09 March 2011 - 12:46 PM

Was This Post Helpful? 2
  • +
  • -

#7 mfaheemriaz   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 23-September 08

Re: What is [controlName].Tag?

Posted 09 March 2011 - 12:50 PM

thanksssssssssssssssss
Was This Post Helpful? 0
  • +
  • -

#8 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6259
  • View blog
  • Posts: 24,028
  • Joined: 23-August 08

Re: What is [controlName].Tag?

Posted 09 March 2011 - 12:55 PM

Here's another suggestion. There's no need to repeat letters like that. It's just silly, and detracts from the professionalism of the forum. A simple "Thanks" would be fine without another 10-15 additional "s" characters.

View Postmfaheemriaz, on 09 March 2011 - 02:44 PM, said:

as i told u i am new here and new to C#, please be polite i was almost going to cry, the way u said, i make that topic so i can find it easily and can also post my problems here....

anyways thanks


It may make it easier for YOU, but it does NOT make it easier for anyone else that comes here, searching for the answer to the same question.
Was This Post Helpful? 0
  • +
  • -

#9 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6537
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: What is [controlName].Tag?

Posted 09 March 2011 - 01:10 PM

View Postmfaheemriaz, on 09 March 2011 - 01:44 PM, said:

as i told u i am new here and new to C#, please be polite i was almost going to cry,


I love to see new people get into coding. But if something as simple as "Please use a meaningful topic for your question so others can find it too" from an anonymous name on a screen while under no pressure at all, nearly drives you to tears then I might suggest you find a new career. In programming you are going to be under a lot of stress and people are going to be a LOT harder on you than that. This might not be a career field you are equipped for.

I wish you the best of luck in learning to code, seeking counseling in coping with the real world, or both - whichever path(s) you choose to undertake.
Was This Post Helpful? 0
  • +
  • -

#10 mfaheemriaz   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 23-September 08

Re: What is [controlName].Tag?

Posted 09 March 2011 - 10:23 PM

View PosttlhIn`toq, on 09 March 2011 - 01:10 PM, said:

View Postmfaheemriaz, on 09 March 2011 - 01:44 PM, said:

as i told u i am new here and new to C#, please be polite i was almost going to cry,


I love to see new people get into coding. But if something as simple as "Please use a meaningful topic for your question so others can find it too" from an anonymous name on a screen while under no pressure at all, nearly drives you to tears then I might suggest you find a new career. In programming you are going to be under a lot of stress and people are going to be a LOT harder on you than that. This might not be a career field you are equipped for.

I wish you the best of luck in learning to code, seeking counseling in coping with the real world, or both - whichever path(s) you choose to undertake.




i can work under pressure and stress but it was my very first topic and i get that response which hurt me, thats why i said, anyways i will be careful next time and one thing more i might be going to submit questions which you might thing that they are silly or common sense questions so please be polite in these questions.
Was This Post Helpful? 0
  • +
  • -

#11 ragingben   User is offline

  • D.I.C Addict
  • member icon

Reputation: 177
  • View blog
  • Posts: 646
  • Joined: 07-October 08

Re: What is [controlName].Tag?

Posted 10 March 2011 - 04:38 AM

What a kefuffle!

Quote

I love to see new people get into coding.
- could not agree with this more - everyone here loves coding, and also loves helping others improve their code. There is a pleasure to be had in helping others, especially when listen to what you are tell them, iunderstand it and it all clicks into place for them.

All I think tlhIn`toq and JackOfAllTrades are trying to say, is please help us to help you by using with clear titles, and responding in a respectful way i.e not using text-talk in your replies.

Then everyone is happy :)

Best of luck in your programming career

This post has been edited by ragingben: 10 March 2011 - 04:39 AM

Was This Post Helpful? 0
  • +
  • -

#12 batesy3k   User is offline

  • D.I.C Regular

Reputation: 41
  • View blog
  • Posts: 299
  • Joined: 10-September 09

Re: What is [controlName].Tag?

Posted 10 March 2011 - 07:52 AM

For example, you could have a TreeView address book and for each tree node (a person) you could associate the .Tag to a object of type Contact thus so:
public class Contact
{
    public string FirstName
    {
        get;
        set;
    }

    public string LastName
    {
        get;
        set;
    }

    public override string ToString()
    {
        return FirstName + " " + LastName;
    }
}


Was This Post Helpful? 0
  • +
  • -

#13 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6537
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: What is [controlName].Tag?

Posted 10 March 2011 - 08:00 AM

View Postbatesy3k, on 10 March 2011 - 08:52 AM, said:

For example, you could have a TreeView address book and for each tree node (a person) you could associate the .Tag to a object of type Contact thus so:
Spoiler


Thanks for providing a code example of my earlier response #6

tlhIn`toq said:

In other words a .Tag can contain any other kind of object. That makes it a very handy property in my book, because it can contain just about anything else.

You could have an treenode, then set it's .Tag property to the object to be used when someone clicks on that node for example.{...}you could set the .Tag to a PersonObj object, override the ToString() method to supply just the name, yet the rest of the object has all their details like age and hair color.

This post has been edited by tlhIn`toq: 10 March 2011 - 08:02 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1