The Tag property of a control in C #

Source: Internet
Author: User
The Tag property is available in many of the control's properties, but how to use it. What is the meaning of tag's use?


Tag itself is the meaning of "label", as the name suggests, is to label the control.
When you have many controls with different type names in your project, you can put the controls on the same label, that is, set the control's tag value to the same value, such as hide, TLB, and so on, and then use a piece of code to do the following:


for (int i = 0; i < ToolStripMain.Items.Count; i++)
{
if (toolstripmain.items[i). Tag = null)
Continue
if (toolstripmain.items[i). Tag.tostring ()!= "TLB")
Continue
Found = false;
if (arr!= null)
{
for (int j = 0; J < arr. Length; J + +)
{
if (arr[j] = = null) continue;
if (arr[j). Btname.toupper () = = Toolstripmain.items[i]. Name.toupper (). ToUpper ())
{
Toolstripmain.items[i]. Enabled = Arr[j]. Enabled;
Toolstripmain.items[i]. Visible = Arr[j]. visuable;
Toolstripmain.items[i]. ToolTipText = Arr[j]. Btdescription;
Found = true;
Hasbuttonshowatleastonece = true;
Break
}
}
}
if (! Found) Toolstripmain.items[i]. Visible = false;
}




Tags are often used to hide controls so that they appear when they are needed.
The use of the Tag property, can be used to bulk manipulate the control, very convenient.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.