本文為機器翻譯文章。如需檢視英文版,請選取 [原文] 核取方塊。您也可以將滑鼠指標移到文字上,即可在快顯視窗顯示英文原文。
譯文
原文

RibbonComponent.Tag 屬性

 

取得或設定與這個 RibbonComponent 相關聯的應用程式特定資料。

命名空間:   Microsoft.Office.Tools.Ribbon
組件:  Microsoft.Office.Tools.Common (於 Microsoft.Office.Tools.Common.dll)

object Tag { get; set; }

屬性值

Type: System.Object

System.Object,代表與這個 RibbonComponent 相關聯的應用程式特定資料。

Any type derived from the System.Object class can be assigned to this property. However, if you set the P:Microsoft.Office.Tools.Ribbon.RibbonComponent.Tag property in the Visual Studio Properties window, you can only assign text.

A common use for the P:Microsoft.Office.Tools.Ribbon.RibbonComponent.Tag property is to store data that is closely associated with the control. For example, if you have a button that displays information about a customer, you might store a System.Data.DataSet that contains the customer's order history in the button's P:Microsoft.Office.Tools.Ribbon.RibbonComponent.Tag property so the data can be accessed quickly.

The following example demonstrates how to set an array of Employee objects to the P:Microsoft.Office.Tools.Ribbon.RibbonComponent.Tag property of a group and how to retrieve the value of the P:Microsoft.Office.Tools.Ribbon.RibbonComponent.Tag property. This example requires that you have defined a class called Employee that exposes the T:System.String property ID and that you have defined a GetEmployees method that returns an array of Employee objects.

To run this code example, you must first perform the following steps:

  1. Add a Ribbon (Visual Designer) item to a project created by using Office development tools in Visual Studio.

  2. Add a button to the default group Group1.

private void button1_Click(object sender, RibbonControlEventArgs e)
{
    // Set the group's Tag property
    group1.Tag = GetEmployees();

    // Show all customers by retrieving them from the group's Tag property
    foreach (Employee emp in (Employee[])group1.Tag)
    {
        System.Windows.Forms.MessageBox.Show(emp.ID);
    }
}
回到頁首
顯示: