单击 选项 在 工具 打开菜单 选项 对话框。 此对话框中选项统称为选项页。 在导航窗格中的树控件包括选项类别,因此,每个类别可选页。 当您选择页时,其选项出现在右窗格中。 这些页可更改用于确定 VSPackage 的状态选项的值。
有关选项页支持
Package 类提供用于创建选项卡页和选项类别支持。 DialogPage 类实现选项页。
DialogPage 的默认实现泛型属性网格的用户提供其公共属性。 您可以用页的各种方法自定义此行为创建具有其自己的用户界面的自定义选项卡页 (UI)。 有关更多信息,请参见 演练:创建选项卡页。
DialogPage 类实现 IProfileManager,提供持久性适用于选项卡页并为用户设置。 ,如果属性可在字符串之间来回转换, LoadSettingsFromStorage 和 SaveSettingsToStorage 方法的默认实现保留属性更改为注册表的用户部分。
选项卡页注册表路径
默认情况下,合并 UserRegistryRoot、单词 DialogPage 和选项卡页类的类型取决于选项卡页托管属性的注册表路径名。 例如,选项卡页类可能的定义如下。
Namespace Company.OptionsPage
Public Class OptionsPageGeneral
Inherits DialogPage
End Class
End Namespace
namespace Company.OptionsPage
{
public class OptionsPageGeneral : DialogPage
{
}
}
如果 UserRegistryRoot 是 HKEY_CURRENT_USER \Software\Microsoft\VisualStudio\8.0Exp, then the property name and value pairs are subkeys of HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\8.0Exp\DialogPage\Company.OptionsPage.OptionsPageGeneral。
合并 ApplicationRegistryRoot取决于选项卡页的注册表路径,单词, ToolsOptionsPages,并且,选项称为类别和名称。 例如,因此,如果自定义选项卡页具有类别,我的选项卡页和 ApplicationRegistryRoot 是 HKEY_LOCAL_MACHINE \SOFTWARE\Microsoft\VisualStudio\8.0Exp, then the options page has the registry key, HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0Exp\ToolsOptionsPages\My Option Pages\Custom。
工具/选项调用属性和布局
ProvideOptionPageAttribute 属性确定分组自定义选项卡页到 选项 对话框的导航树的类别。 ProvideOptionPageAttribute 关联的属性选项页与提供接口的 VSPackage。 考虑以下代码片断:
<ProvideOptionPage(GetType(OptionsPageGeneral), "My Option Pages", "General", 101, 106, True),
ProvideOptionPage(GetType(OptionsPageCustom), "My Option Pages", "Custom", 101, 107, True),
Guid("B0002DC2-56EE-4931-93F7-70D6E9863940")>
Public Class MyPackage
Inherits Package
[ProvideOptionPage(typeof(OptionsPageGeneral),"My Option Pages", "General", 101, 106, true)]
[ProvideOptionPage(typeof(OptionsPageCustom), "My Option Pages", "Custom", 101, 107, true)]
[Guid("B0002DC2-56EE-4931-93F7-70D6E9863940")]
public class MyPackage : Package
该声明 Mypackage::close() 提供两个选项卡页、 OptionsPageGeneral 和 OptionsPageCustom。 在 选项 对话框中,两个选项页出现在 我的选项卡页 分类为 泛型 和 自定义,分别。
可选特性和布局
页 (UI)提供的用户界面定位选项外观在自定义选项卡页的。 以下属性取决于选项卡的布局,标记和说明在 " 常规 " 选项卡页的:
CategoryAttribute 确保选项的类别。
DisplayNameAttribute 确保选项的显示名称。
DescriptionAttribute 确保选项的说明。
备注
等效属性、 SRCategory、 LocDisplayName 和 SRDescription,使用本地化的字符串资源并在中定义 managed project sample。
考虑以下代码片断:
Private _optionInt As Integer
<Category("My Options"),
DisplayName("Integer Option"),
Description("My integer option")>
Public Property OptionInteger() As Integer
Get
Return _optionInt
End Get
Set(ByVal value As Integer)
_optionInt = value
End Set
End Property
[Category("My Options")]
[DisplayName("Integer Option")]
[Description("My integer option")]
public int OptionInteger { get; set; }
OptionInteger 选项出现在选项卡页为 我的选项 类别的 整数选项 。 如果该选项处于选中状态,声明, 我的整数选项,将出现在声明框。
从其他 VSPackage 中访问的选项卡页
承载和管理选项卡页使用自动化模型,的 VSPackage 可以以编程方式从另一 VSPackage 访问。 例如,在下面的代码 VSPackage 注册为承载选项页。
<ProvideOptionPage(GetType(MyOptionPage), "My Category", "My Grid Page", 0, 0, True)>
<Guid("6bb6942e-014c-489e-a612-a935680f703d")>
Public NotInheritable Class MyToolsOptions
Inherits Package
[ProvideOptionPage(typeof(MyOptionPage), "My Category", "My Grid Page", 0, 0, true)]
[Guid("6bb6942e-014c-489e-a612-a935680f703d")]
public sealed class MyToolsOptions : Package
下面的代码片段从 MyOptionPage 获取 OptionInteger 的值:
Dim dte As DTE = CType(GetService(GetType(DTE)), DTE)
Dim props As EnvDTE.Properties = dte.get_Properties("My Category", "My Grid Page")
Dim n As Integer = CInt(Fix(props.Item("OptionInteger").Value))
DTE dte = (DTE)GetService(typeof(DTE));
EnvDTE.Properties props = dte.get_Properties("My Category", "My Grid Page");
int n = (int)props.Item("OptionInteger").Value;
当 ProvideOptionPageAttribute 属性注册选项页,该页签入 AutomationProperties 项下,如果属性的 SupportsAutomation 参数是 true。 自动检查此注册表项通过承载的选项卡页查找关联的 VSPackage 和自动化然后访问属性,在本例中,我的网格页。
合并 ApplicationRegistryRoot取决于自动化属性的注册表路径,单词, AutomationProperties,并且,选项称为类别和名称。 例如,因此,如果选项卡页具有我的类别分类 "、 " 我的网格页名称和 ApplicationRegistryRoot, HKEY_LOCAL_MACHINE \SOFTWARE\Microsoft\VisualStudio\8.0Exp, then the automation property has the registry key, HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0Exp\AutomationProperties\My Category\My Grid Page。
备注
规范名称,我的 Category.My 网格页,这就是键名称子项的值。