HOW TO:控制動態說明視窗
更新:2007 年 11 月
Visual Studio 具有 [動態說明] 視窗,會根據使用者的內容提供相關說明主題的連結。例如,如果您開始在程式碼編輯器中進行編輯,[動態說明] 視窗中便會顯示如何使用程式碼編輯器的主題。它的運作方式是,將與目前內容相關的關鍵字和與說明主題有關聯的關鍵字清單做個比較,然後找出相關內容再加以顯示。
ContextAttributes 集合和 ContextAttribute 物件可以讓您列出適用於 Visual Studio 所指定之視窗的關鍵字集合,也可以讓您加入屬性 (Attribute) 並排列優先順序。因此,當 Automation 用戶端選取視窗或視窗中的項目 (例如索引標籤或連結) 時,便可以在 [動態說明] 視窗中顯示他們所選擇的主題。
ContextAttribute 物件表示特定視窗或視窗項目的內容,ContextAttributes 則是指定視窗中所有 ContextAttribute 物件的集合。內容由三種內容類型構成:Filter、Lookup 及 LookupF1:
Filter |
將屬性加入內容集合。屬性是名稱/值的組合,用來篩選 [動態說明] 視窗中所顯示的 F1 和查詢關鍵字主題,或是用來篩選當使用者按下 F1 時所顯示的主題。 |
Lookup |
將關鍵字加入內容集合。與此關鍵字對應的主題會顯示在 [動態說明] 視窗中。查詢關鍵字會提供顯示在 [動態說明] 視窗中的背景或相關主題的清單。當使用者變更目前的選取範圍時,[動態說明] 視窗中的關鍵字主題清單也會隨之更新。查詢關鍵字是由編譯後之說明檔索引中顯示之關鍵字相同的來源衍生。 |
LookupF1 |
與此關鍵字對應的主題會顯示在 [動態說明] 視窗中,並且用來尋找 F1 說明主題。F1 關鍵字會在選取內容項目 (例如工具視窗、編輯器或強制回應對話方塊),或按下 F1 時提供說明主題。F1 關鍵字主題也會列在 [動態說明] 視窗中。F1 關鍵字會加入內容集合中。 |
有三種內容屬性會指示產生 ContextAttributes 物件的位置:
Global |
全域整合式開發環境 (IDE) 內容。 |
High Priority |
High Priority 內容集合。High Priority 內容屬性表示主題連結會顯示在 [動態說明] 視窗中其連結群組的最上方。 |
Window |
視窗內容。 |
ContextAttributes 集合可以由下列物件提供:
會影響全域內容集合,這種集合的排序主題優先順序最低。 |
|
會影響視窗的內容集合。用於工具視窗時,只有在選取視窗時這些屬性才會生效。用於編輯器和設計工具時,只要編輯器是最後一個作用中 MDI 子視窗,屬性就會生效。如果 HighPriorityAttributes 屬性的值為 True,則這些屬性永遠都有效,而且擁有最高的優先順序。 |
當您使關鍵字與視窗或視窗項目產生關聯之後,就可以用它來顯示說明主題。您可以使用 XML Help Provider 顯示自訂的說明主題或 URL。如需詳細資訊,請在 Visual Studio Industry Partner (VSIP) SDK 說明中搜尋 "XML Help Provider and Dynamic Help"。
除了控制 [動態說明] 視窗的內容外,您也可以控制寬度和高度等特性。如需詳細資訊,請參閱 HOW TO:變更視窗特性。
使用 ContextAttributes 和 ContextAttribute,您可以:
加入或移除關鍵字名稱、值及類型
取得關鍵字的名稱和值
取得 High Priority 屬性的清單做為 DTE.ContextAttributes 的 ContextAttributes 集合。
![]() |
---|
根據目前使用的設定與版本,您所看到的對話方塊與功能表命令可能會與 [說明] 中所描述的不同。已使用 [一般開發設定] 開發了這些程序。若要變更設定,請從 [工具] 功能表中選擇 [匯入和匯出設定]。如需詳細資訊,請參閱 Visual Studio 設定。 |
範例
在這個增益集 (Add-In) 範例中,會示範如何參考及使用 [動態說明] Automation 模型的各個成員。這個範例會列出與 [方案總管] 有關聯的關鍵字名稱和數目。此外,也會在其中加入新的 F1 關鍵字,然後再移除。如需如何將範例當做增益集或當做 Visual Studio 巨集執行的詳細資訊,請參閱 HOW TO:編譯和執行 Automation 物件模型程式碼範例。
Public Sub OnConnection(ByVal application As Object, ByVal _
connectMode As ext_ConnectMode, ByVal addInInst As Object, _
ByRef custom As Array) Implements IDTExtensibility2.OnConnection
_applicationObject = CType(application, DTE2)
_addInInstance = CType(addInInst, AddIn)
' Pass the applicationObject member variable to the code example.
CATest(_applicationObject)
End Sub
Sub CATest(ByVal dte As DTE2)
' Get a reference to Solution Explorer.
Dim SolnEx As Window = _applicationObject.Windows.Item(Constants. _
vsWindowKindSolutionExplorer)
Dim CA As ContextAttribute
' List the current attributes associated with Solution Explorer.
ListAttr(SolnEx, CA)
' Associate a new F1 keyword to Solution Explorer.
SolnEx.ContextAttributes.Add("ANewKeyword", "900", _
vsContextAttributeType.vsContextAttributeLookupF1)
ListAttr(SolnEx, CA)
' Delete the new F1 keyword from Solution Explorer.
SolnEx.ContextAttributes.Item(3).Remove()
ListAttr(SolnEx, CA)
End Sub
Sub ListAttr(ByVal SolnEx As Object, ByVal CA As ContextAttribute)
' Support function for CATest(). Lists the current attributes
' associated with Solution Explorer.
Dim msg As String
msg = ""
MsgBox("Number of context attributes in Solution Explorer: " _
& SolnEx.ContextAttributes.Count)
For Each CA In SolnEx.ContextAttributes
msg = msg & CA.Name & Chr(13)
Next
MsgBox(msg)
msg = ""
End Sub
public void OnConnection(object application,
Extensibility.ext_ConnectMode connectMode, object addInInst, ref
System.Array custom)
{
_applicationObject = (DTE2)application;
_addInInstance = (AddIn)addInInst;
// Pass the applicationObject member variable to the code example.
CATest(_applicationObject);
}
public void CATest( DTE2 dte )
{
// Add-in code.
// Get a reference to Solution Explorer.
Window SolnEx = dte.Windows.Item
( Constants.vsWindowKindSolutionExplorer );
ContextAttribute CA = null;
// List the current attributes associated with Solution Explorer.
ListAttr( SolnEx, CA );
// Associate a new F1 keyword to Solution Explorer.
SolnEx.ContextAttributes.Add( "ANewKeyword",
System.Convert.ToString(900),
vsContextAttributeType.vsContextAttributeLookupF1 );
ListAttr( SolnEx, CA );
// Delete the new F1 keyword from Solution Explorer.
SolnEx.ContextAttributes.Item( 2 ).Remove();
ListAttr( SolnEx, CA );
}
public void ListAttr( EnvDTE.Window SolnEx, ContextAttribute CA )
{
// Support function for CATest(). Lists the current attributes
// associated with Solution Explorer.
string msg = null;
MessageBox.Show
( "Number of context attributes in Solution Explorer: "
+ SolnEx.ContextAttributes.Count);
foreach ( EnvDTE.ContextAttribute temp in
SolnEx.ContextAttributes )
{
CA = temp;
msg = msg + CA.Name + "\n";
}
MessageBox.Show( msg);
msg = "";
}