DesignerOptionService Clase
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Proporciona una clase base para obtener y establecer valores de opciones de un diseñador.
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
- Herencia
-
DesignerOptionService
- Derivado
- Implementaciones
Ejemplos
En el ejemplo de código siguiente se muestra el acceso DesignerOptionService a para mostrar los valores actuales de las opciones estándar.
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
Comentarios
La DesignerOptionService clase proporciona una colección de opciones. Cada una de estas colecciones de opciones tiene un indexador que le permite filtrarse aún más. Cada colección de opciones contiene su propio conjunto de opciones, así como un resumen de todas sus opciones secundarias. En caso de conflicto de nomenclatura entre propiedades, el objeto de opciones más externo tiene prioridad. Las siguientes herramientas | La estructura de la interfaz de usuario de opciones (UI) muestra cómo el objeto de opciones más externo tiene mayor importancia:
WindowsFormsDesigner | General
SnapToGrid
Showgrid
GridSize
Dado un IDesignerOptionService elemento con nombre service
, para obtener el valor de la GridSize propiedad , debe realizar la siguiente llamada:
// 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)
Esto funciona hasta que quiera mover GridSize a otra página. Además, IDesignerOptionService no proporciona ningún mecanismo de detección. Si no sabe qué cadena se va a pasar, el servicio no puede encontrar el valor de la propiedad.
La DesignerOptionService clase soluciona estos problemas. Puede consultar colecciones y hay un convertidor de tipos definido en el DesignerOptionService.DesignerOptionCollection objeto que marca la colección como expandible. Con este convertidor de tipos, puede pasar todo el servicio de opciones del diseñador a una ventana de propiedades e inspeccionar visualmente el servicio.
Constructores
DesignerOptionService() |
Inicializa una nueva instancia de la clase DesignerOptionService. |
Propiedades
Options |
Obtiene la colección de opciones para este servicio. |
Métodos
CreateOptionCollection(DesignerOptionService+DesignerOptionCollection, String, Object) |
Crea un nuevo objeto DesignerOptionService.DesignerOptionCollection con el nombre especificado y lo agrega al elemento primario establecido. |
Equals(Object) |
Determina si el objeto especificado es igual que el objeto actual. (Heredado de Object) |
GetHashCode() |
Sirve como la función hash predeterminada. (Heredado de Object) |
GetType() |
Obtiene el Type de la instancia actual. (Heredado de Object) |
MemberwiseClone() |
Crea una copia superficial del Object actual. (Heredado de Object) |
PopulateOptionCollection(DesignerOptionService+DesignerOptionCollection) |
Rellena una colección DesignerOptionService.DesignerOptionCollection. |
ShowDialog(DesignerOptionService+DesignerOptionCollection, Object) |
Muestra el cuadro de diálogo de opciones para el objeto especificado. |
ToString() |
Devuelve una cadena que representa el objeto actual. (Heredado de Object) |
Implementaciones de interfaz explícitas
IDesignerOptionService.GetOptionValue(String, String) |
Obtiene el valor de una opción definida en este paquete. |
IDesignerOptionService.SetOptionValue(String, String, Object) |
Establece el valor de una opción definida en este paquete. |