DesignerOptionService Classe
Definição
Fornece uma classe base para obter e configurar valores de opção para um designer.Provides a base class for getting and setting option values for a designer.
public ref class DesignerOptionService abstract : System::ComponentModel::Design::IDesignerOptionService
public abstract class DesignerOptionService : System.ComponentModel.Design.IDesignerOptionService
type DesignerOptionService = class
interface IDesignerOptionService
Public MustInherit Class DesignerOptionService
Implements IDesignerOptionService
- Herança
-
DesignerOptionService
- Derivado
- Implementações
Exemplos
O exemplo de código a seguir demonstra DesignerOptionService como acessar o para exibir os valores atuais das opções padrão.The following code example demonstrates accessing the DesignerOptionService to display the current values of the standard options.
using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Windows.Forms.Design;
namespace DesignerOptionServiceExample
{
// This control demonstrates retrieving the standard
// designer option service values in design mode.
public class DesignerOptionServiceControl : System.Windows.Forms.UserControl
{
private DesignerOptionService designerOptionSvc;
public DesignerOptionServiceControl()
{
this.BackColor = Color.Beige;
this.Size = new Size(404, 135);
}
public override System.ComponentModel.ISite Site
{
get
{
return base.Site;
}
set
{
base.Site = value;
// If siting component, attempt to obtain an DesignerOptionService.
if( base.Site != null )
designerOptionSvc = (DesignerOptionService)this.GetService(typeof(DesignerOptionService));
}
}
// Displays control information and current DesignerOptionService
// values, if available.
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
e.Graphics.DrawString("DesignerOptionServiceControl",
new Font("Arial", 9),
new SolidBrush(Color.Blue), 4, 4);
if( this.DesignMode )
e.Graphics.DrawString("Currently in design mode",
new Font("Arial", 8),
new SolidBrush(Color.Black), 4, 18);
else
e.Graphics.DrawString("Not in design mode. Cannot access DesignerOptionService.",
new Font("Arial", 8),
new SolidBrush(Color.Red), 4, 18);
if( base.Site != null && designerOptionSvc != null )
{
e.Graphics.DrawString("DesignerOptionService provides access to the table of option values listed when",
new Font("Arial", 8),
new SolidBrush(Color.Black), 4, 38);
e.Graphics.DrawString("the Windows Forms Designer\\General tab of the Tools\\Options menu is selected.",
new Font("Arial", 8),
new SolidBrush(Color.Black), 4, 50);
e.Graphics.DrawString("Table of standard value names and current values",
new Font("Arial", 8),
new SolidBrush(Color.Red), 4, 76);
// Displays a table of the standard value names and current values.
int ypos = 90;
// Obtains and shows the size of the standard design-mode grid square.
PropertyDescriptor pd;
pd = designerOptionSvc.Options.Properties["GridSize"];
e.Graphics.DrawString("GridSize",
new Font("Arial", 8),
new SolidBrush(Color.Black), 4, ypos);
e.Graphics.DrawString(pd.GetValue(null).ToString(),
new Font("Arial", 8),
new SolidBrush(Color.Black), 200, ypos);
ypos += 12;
// Uncomment the following code to demonstrate that this
// alternate syntax works the same as the previous syntax.
//pd = designerOptionSvc.Options["WindowsFormsDesigner"].Properties["GridSize"];
//e.Graphics.DrawString("GridSize",
// new Font("Arial", 8),
// new SolidBrush(Color.Black), 4, ypos);
//e.Graphics.DrawString(pd.GetValue(null).ToString(),
// new Font("Arial", 8),
// new SolidBrush(Color.Black), 200, ypos);
//ypos += 12;
//pd = designerOptionSvc.Options["WindowsFormsDesigner"]["General"].Properties["GridSize"];
//e.Graphics.DrawString("GridSize",
// new Font("Arial", 8),
// new SolidBrush(Color.Black), 4, ypos);
//e.Graphics.DrawString(pd.GetValue(null).ToString(),
// new Font("Arial", 8),
// new SolidBrush(Color.Black), 200, ypos);
//ypos += 12;
// Obtains and shows whether the design mode surface grid is enabled.
pd = designerOptionSvc.Options.Properties["ShowGrid"];
e.Graphics.DrawString("ShowGrid",
new Font("Arial", 8),
new SolidBrush(Color.Black), 4, ypos);
e.Graphics.DrawString(pd.GetValue(null).ToString(),
new Font("Arial", 8),
new SolidBrush(Color.Black), 200, ypos);
ypos+=12;
// Obtains and shows whether components should be aligned with the surface grid.
pd = designerOptionSvc.Options.Properties["SnapToGrid"];
e.Graphics.DrawString("SnapToGrid",
new Font("Arial", 8),
new SolidBrush(Color.Black), 4, ypos);
e.Graphics.DrawString(pd.GetValue(null).ToString(),
new Font("Arial", 8),
new SolidBrush(Color.Black), 200, ypos);
ypos += 12;
// Obtains and shows which layout mode is selected.
pd = designerOptionSvc.Options.Properties["LayoutMode"];
e.Graphics.DrawString("LayoutMode",
new Font("Arial", 8),
new SolidBrush(Color.Black), 4, ypos);
e.Graphics.DrawString(pd.GetValue(null).ToString(),
new Font("Arial", 8),
new SolidBrush(Color.Black), 200, ypos);
ypos += 12;
// Obtains and shows whether the Toolbox is automatoically
// populated with custom controls and components.
pd = designerOptionSvc.Options.Properties["AutoToolboxPopulate"];
e.Graphics.DrawString("AutoToolboxPopulate",
new Font("Arial", 8),
new SolidBrush(Color.Black), 4, ypos);
e.Graphics.DrawString(pd.GetValue(null).ToString(),
new Font("Arial", 8),
new SolidBrush(Color.Black), 200, ypos);
ypos += 12;
// Obtains and shows whether the component cache is used.
pd = designerOptionSvc.Options.Properties["UseOptimizedCodeGeneration"];
e.Graphics.DrawString("Optimized Code Generation",
new Font("Arial", 8),
new SolidBrush(Color.Black), 4, ypos);
e.Graphics.DrawString(pd.GetValue(null).ToString(),
new Font("Arial", 8),
new SolidBrush(Color.Black), 200, ypos);
ypos += 12;
// Obtains and shows whether designer actions are automatically opened.
pd = designerOptionSvc.Options.Properties["ObjectBoundSmartTagAutoShow"];
e.Graphics.DrawString("Automatically Open Designer Actions",
new Font("Arial", 8),
new SolidBrush(Color.Black), 4, ypos);
e.Graphics.DrawString(pd.GetValue(null).ToString(),
new Font("Arial", 8),
new SolidBrush(Color.Black), 200, ypos);
}
}
}
}
Imports System.Collections
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Drawing
Imports System.Data
Imports System.Windows.Forms
Imports System.Windows.Forms.Design
' This control demonstrates retrieving the standard
' designer option service values in design mode.
Public Class DesignerOptionServiceControl
Inherits System.Windows.Forms.UserControl
Private designerOptionSvc As DesignerOptionService
Public Sub New()
Me.BackColor = Color.Beige
Me.Size = New Size(404, 135)
End Sub
Public Overrides Property Site() As System.ComponentModel.ISite
Get
Return MyBase.Site
End Get
Set
MyBase.Site = value
' If siting component, attempt to obtain an DesignerOptionService.
If (MyBase.Site IsNot Nothing) Then
designerOptionSvc = CType(Me.GetService(GetType(DesignerOptionService)), DesignerOptionService)
End If
End Set
End Property
' Displays control information and current DesignerOptionService
' values, if available.
Protected Overrides Sub OnPaint(e As System.Windows.Forms.PaintEventArgs)
e.Graphics.DrawString("DesignerOptionServiceControl", _
New Font("Arial", 9), _
New SolidBrush(Color.Blue), 4, 4)
If Me.DesignMode Then
e.Graphics.DrawString("Currently in design mode", _
New Font("Arial", 8), _
New SolidBrush(Color.Black), 4, 18)
Else
e.Graphics.DrawString("Not in design mode. Cannot access DesignerOptionService.", _
New Font("Arial", 8), _
New SolidBrush(Color.Red), 4, 18)
End If
If (MyBase.Site IsNot Nothing) AndAlso (designerOptionSvc IsNot Nothing) Then
e.Graphics.DrawString("DesignerOptionService provides access to the table of option values listed when", _
New Font("Arial", 8), _
New SolidBrush(Color.Black), 4, 38)
e.Graphics.DrawString("the Windows Forms Designer\General tab of the Tools\Options menu is selected.", _
New Font("Arial", 8), _
New SolidBrush(Color.Black), 4, 50)
e.Graphics.DrawString("Table of standard value names and current values", _
New Font("Arial", 8), _
New SolidBrush(Color.Red), 4, 76)
' Displays a table of the standard value names and current values.
Dim ypos As Integer = 90
' Obtains and shows the size of the standard design-mode grid square.
Dim pd As PropertyDescriptor
pd = designerOptionSvc.Options.Properties("GridSize")
e.Graphics.DrawString("GridSize", _
New Font("Arial", 8), _
New SolidBrush(Color.Black), 4, ypos)
e.Graphics.DrawString(pd.GetValue(Nothing).ToString(), _
New Font("Arial", 8), _
New SolidBrush(Color.Black), 200, ypos)
ypos += 12
' Uncomment the following code to demonstrate that this
' alternate syntax works the same as the previous syntax.
'pd = designerOptionSvc.Options["WindowsFormsDesigner"].Properties["GridSize"];
'e.Graphics.DrawString("GridSize",
' new Font("Arial", 8),
' new SolidBrush(Color.Black), 4, ypos);
'e.Graphics.DrawString(pd.GetValue(null).ToString(),
' new Font("Arial", 8),
' new SolidBrush(Color.Black), 200, ypos);
'ypos += 12;
'pd = designerOptionSvc.Options["WindowsFormsDesigner"]["General"].Properties["GridSize"];
'e.Graphics.DrawString("GridSize",
' new Font("Arial", 8),
' new SolidBrush(Color.Black), 4, ypos);
'e.Graphics.DrawString(pd.GetValue(null).ToString(),
' new Font("Arial", 8),
' new SolidBrush(Color.Black), 200, ypos);
'ypos += 12;
' Obtains and shows whether the design mode surface grid is enabled.
pd = designerOptionSvc.Options.Properties("ShowGrid")
e.Graphics.DrawString("ShowGrid", _
New Font("Arial", 8), _
New SolidBrush(Color.Black), 4, ypos)
e.Graphics.DrawString(pd.GetValue(Nothing).ToString(), _
New Font("Arial", 8), _
New SolidBrush(Color.Black), 200, ypos)
ypos += 12
' Obtains and shows whether components should be aligned with the surface grid.
pd = designerOptionSvc.Options.Properties("SnapToGrid")
e.Graphics.DrawString("SnapToGrid", _
New Font("Arial", 8), _
New SolidBrush(Color.Black), 4, ypos)
e.Graphics.DrawString(pd.GetValue(Nothing).ToString(), _
New Font("Arial", 8), _
New SolidBrush(Color.Black), 200, ypos)
ypos += 12
' Obtains and shows which layout mode is selected.
pd = designerOptionSvc.Options.Properties("LayoutMode")
e.Graphics.DrawString("LayoutMode", _
New Font("Arial", 8), _
New SolidBrush(Color.Black), 4, ypos)
e.Graphics.DrawString(pd.GetValue(Nothing).ToString(), _
New Font("Arial", 8), _
New SolidBrush(Color.Black), 200, ypos)
ypos += 12
' Obtains and shows whether the Toolbox is automatoically
' populated with custom controls and components.
pd = designerOptionSvc.Options.Properties("AutoToolboxPopulate")
e.Graphics.DrawString("AutoToolboxPopulate", _
New Font("Arial", 8), _
New SolidBrush(Color.Black), 4, ypos)
e.Graphics.DrawString(pd.GetValue(Nothing).ToString(), _
New Font("Arial", 8), _
New SolidBrush(Color.Black), 200, ypos)
ypos += 12
' Obtains and shows whether the component cache is used.
pd = designerOptionSvc.Options.Properties("UseOptimizedCodeGeneration")
e.Graphics.DrawString("Optimized Code Generation", _
New Font("Arial", 8), _
New SolidBrush(Color.Black), 4, ypos)
e.Graphics.DrawString(pd.GetValue(Nothing).ToString(), _
New Font("Arial", 8), _
New SolidBrush(Color.Black), 200, ypos)
ypos += 12
' Obtains and shows whether designer actions are automatically opened.
pd = designerOptionSvc.Options.Properties("ObjectBoundSmartTagAutoShow")
e.Graphics.DrawString("Automatically Open Designer Actions", _
New Font("Arial", 8), _
New SolidBrush(Color.Black), 4, ypos)
e.Graphics.DrawString(pd.GetValue(Nothing).ToString(), _
New Font("Arial", 8), _
New SolidBrush(Color.Black), 200, ypos)
End If
End Sub
End Class
Comentários
A DesignerOptionService classe fornece uma coleção de opções.The DesignerOptionService class provides a collection of options. Cada uma dessas coleções de opções tem um indexador que permite que ele seja filtrado ainda mais.Each of these option collections has an indexer that enables it to be further filtered. Cada coleção de opções contém seu próprio conjunto de opções, bem como um acúmulo de todas as suas opções filho.Each option collection contains its own set of options, as well as a rollup of all of its child options. No caso de um conflito de nomenclatura entre propriedades, o objeto de opções mais externo tem precedência.In the event of a naming conflict between properties, the outermost options object takes precedence. As seguintes ferramentas | estrutura de interface do usuário de opções (IU) mostra como o objeto de opções mais externo assume maior importância:The following Tools | Options user interface (UI) structure shows how the outermost options object takes on greater importance:
WindowsFormsDesigner | geralWindowsFormsDesigner | General
SnapToGridSnapToGrid
Obter gradeShowGrid
GridSizeGridSize
Dado um IDesignerOptionService nome service , para chegar ao valor da GridSize propriedade, você faria a seguinte chamada:Given a IDesignerOptionService named service, to get to the value of the GridSize property, you would make the following call:
// Obtains and shows the size of the standard design-mode grid square.
System::Drawing::Size size = *dynamic_cast<System::Drawing::Size^>(designerOptionService->GetOptionValue( "WindowsFormsDesigner\\General", "GridSize" ));
// Obtains and shows the size of the standard design-mode grid square.
Size size = (Size)designerOptionService.GetOptionValue("WindowsFormsDesigner\\General", "GridSize");
' Obtains and shows the size of the standard design-mode grid square.
Dim size As Size = CType(designerOptionService.GetOptionValue("WindowsFormsDesigner\General", "GridSize"), Size)
Isso funciona até que você queira mover GridSize para outra página.This works, until you want to move GridSize to another page. Além disso, o IDesignerOptionService não fornece nenhum mecanismo de descoberta.Also, IDesignerOptionService provides no discovery mechanism. Se você não souber qual cadeia de caracteres transmitir, o serviço não poderá localizar o valor da propriedade.If you do not know what string to pass in, the service cannot find the property value.
A DesignerOptionService classe resolve esses problemas.The DesignerOptionService class addresses these issues. Você pode consultar coleções e há um conversor de tipo definido no DesignerOptionService.DesignerOptionCollection objeto que marca a coleção como expansível.You can query collections, and there is a type converter defined on the DesignerOptionService.DesignerOptionCollection object that marks the collection as expandable. Com esse conversor de tipo, você pode passar o serviço de opção de designer inteiro para uma janela de propriedades e inspecionar visualmente o serviço.With this type converter, you can pass the entire designer option service to a property window and visually inspect the service.
Construtores
| DesignerOptionService() |
Inicializa uma nova instância da classe DesignerOptionService.Initializes a new instance of the DesignerOptionService class. |
Propriedades
| Options |
Obtém a coleção de opções para este serviço.Gets the options collection for this service. |
Métodos
| CreateOptionCollection(DesignerOptionService+DesignerOptionCollection, String, Object) |
Cria uma nova DesignerOptionService.DesignerOptionCollection com o nome fornecido e adiciona-a ao pai especificado.Creates a new DesignerOptionService.DesignerOptionCollection with the given name and adds it to the given parent. |
| Equals(Object) |
Determina se o objeto especificado é igual ao objeto atual.Determines whether the specified object is equal to the current object. (Herdado de Object) |
| GetHashCode() |
Serve como a função de hash padrão.Serves as the default hash function. (Herdado de Object) |
| GetType() |
Obtém o Type da instância atual.Gets the Type of the current instance. (Herdado de Object) |
| MemberwiseClone() |
Cria uma cópia superficial do Object atual.Creates a shallow copy of the current Object. (Herdado de Object) |
| PopulateOptionCollection(DesignerOptionService+DesignerOptionCollection) |
Popula uma DesignerOptionService.DesignerOptionCollection.Populates a DesignerOptionService.DesignerOptionCollection. |
| ShowDialog(DesignerOptionService+DesignerOptionCollection, Object) |
Mostra a caixa de diálogo de opções para o objeto fornecido.Shows the options dialog box for the given object. |
| ToString() |
Retorna uma cadeia de caracteres que representa o objeto atual.Returns a string that represents the current object. (Herdado de Object) |
Implantações explícitas de interface
| IDesignerOptionService.GetOptionValue(String, String) |
Obtém o valor de uma opção definida neste pacote.Gets the value of an option defined in this package. |
| IDesignerOptionService.SetOptionValue(String, String, Object) |
Define o valor de uma opção definida neste pacote.Sets the value of an option defined in this package. |