IDesignerOptionService-Schnittstelle
Bietet Zugriff auf die Designeroptionen, die sich in der Visual Studio .NET-Entwicklungsumgebung im Menü Extras unter dem Befehl Optionen befinden.
Namespace: System.ComponentModel.Design
Assembly: System (in system.dll)
Syntax
'Declaration
Public Interface IDesignerOptionService
'Usage
Dim instance As IDesignerOptionService
public interface IDesignerOptionService
public interface class IDesignerOptionService
public interface IDesignerOptionService
public interface IDesignerOptionService
Hinweise
IDesignerOptionService stellt eine Schnittstelle zum Abrufen und Aktualisieren der Werte der Windows Forms-Designer-Optionen bereit, die in dem Dialogfeld aufgelistet sind, das über den Befehl Optionen des Menüs Extras der Visual Studio-Entwicklungsumgebung angezeigt wird. Die GetOptionValue-Methode ruft den Wert einer angegebenen Option ab. Die SetOptionValue-Methode legt einen angegebenen Wert für eine angegebene Option fest.
Beispiel
Im folgenden Codebeispiel wird das Zugreifen auf IDesignerOptionService zum Anzeigen der aktuellen Werte der Standardoptionen veranschaulicht.
Imports System
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 IDesignerOptionServiceControl
Inherits System.Windows.Forms.UserControl
Private designerOptionService As IDesignerOptionService
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(ByVal Value As System.ComponentModel.ISite)
MyBase.Site = Value
' If siting component, attempt to obtain an IDesignerOptionService.
If Not (MyBase.Site Is Nothing) Then
designerOptionService = CType(Me.GetService(GetType(IDesignerOptionService)), IDesignerOptionService)
End If
End Set
End Property
' Displays control information and current IDesignerOptionService
' values, if available.
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
e.Graphics.DrawString("IDesignerOptionServiceControl", 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 IDesignerOptionService.", New Font("Arial", 8), New SolidBrush(Color.Red), 4, 18)
End If
If Not (MyBase.Site Is Nothing) AndAlso Not (designerOptionService Is Nothing) Then
e.Graphics.DrawString("IDesignerOptionService 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 size As Size = CType(designerOptionService.GetOptionValue("WindowsFormsDesigner\General", "GridSize"), Size)
e.Graphics.DrawString("GridSize", New Font("Arial", 8), New SolidBrush(Color.Black), 4, ypos)
e.Graphics.DrawString(size.ToString(), New Font("Arial", 8), New SolidBrush(Color.Black), 100, ypos)
ypos += 12
' Obtaisn and shows whether the design mode surface grid is enabled.
Dim showGrid As Boolean = CBool(designerOptionService.GetOptionValue("WindowsFormsDesigner\General", "ShowGrid"))
e.Graphics.DrawString("ShowGrid", New Font("Arial", 8), New SolidBrush(Color.Black), 4, ypos)
e.Graphics.DrawString(showGrid.ToString(), New Font("Arial", 8), New SolidBrush(Color.Black), 100, ypos)
ypos += 12
' Obtains and shows whether components should be aligned with the surface grid.
Dim snapToGrid As Boolean = CBool(designerOptionService.GetOptionValue("WindowsFormsDesigner\General", "SnapToGrid"))
e.Graphics.DrawString("SnapToGrid", New Font("Arial", 8), New SolidBrush(Color.Black), 4, ypos)
e.Graphics.DrawString(snapToGrid.ToString(), New Font("Arial", 8), New SolidBrush(Color.Black), 100, ypos)
End If
End Sub
End Class
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 IDesignerOptionServiceExample
{
// This control demonstrates retrieving the standard
// designer option service values in design mode.
public class IDesignerOptionServiceControl : System.Windows.Forms.UserControl
{
private IDesignerOptionService designerOptionService;
public IDesignerOptionServiceControl()
{
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 IDesignerOptionService.
if( base.Site != null )
designerOptionService = (IDesignerOptionService)this.GetService(typeof(IDesignerOptionService));
}
}
// Displays control information and current IDesignerOptionService
// values, if available.
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
e.Graphics.DrawString("IDesignerOptionServiceControl", 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 IDesignerOptionService.", new Font("Arial", 8), new SolidBrush(Color.Red), 4, 18);
if( base.Site != null && designerOptionService != null )
{
e.Graphics.DrawString("IDesignerOptionService 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.
Size size = (Size)designerOptionService.GetOptionValue("WindowsFormsDesigner\\General", "GridSize");
e.Graphics.DrawString("GridSize", new Font("Arial", 8), new SolidBrush(Color.Black), 4, ypos);
e.Graphics.DrawString(size.ToString(), new Font("Arial", 8), new SolidBrush(Color.Black), 100, ypos);
ypos+=12;
// Obtains and shows whether the design mode surface grid is enabled.
bool showGrid = (bool)designerOptionService.GetOptionValue("WindowsFormsDesigner\\General", "ShowGrid");
e.Graphics.DrawString("ShowGrid", new Font("Arial", 8), new SolidBrush(Color.Black), 4, ypos);
e.Graphics.DrawString(showGrid.ToString(), new Font("Arial", 8), new SolidBrush(Color.Black), 100, ypos);
ypos+=12;
// Obtains and shows whether components should be aligned with the surface grid.
bool snapToGrid = (bool)designerOptionService.GetOptionValue("WindowsFormsDesigner\\General", "SnapToGrid");
e.Graphics.DrawString("SnapToGrid", new Font("Arial", 8), new SolidBrush(Color.Black), 4, ypos);
e.Graphics.DrawString(snapToGrid.ToString(), new Font("Arial", 8), new SolidBrush(Color.Black), 100, ypos);
}
}
}
}
#using <System.Windows.Forms.dll>
#using <System.Data.dll>
#using <System.Drawing.dll>
#using <System.dll>
using namespace System;
using namespace System::Collections;
using namespace System::ComponentModel;
using namespace System::ComponentModel::Design;
using namespace System::Drawing;
using namespace System::Data;
using namespace System::Windows::Forms;
using namespace System::Windows::Forms::Design;
namespace IDesignerOptionServiceExample
{
// This control demonstrates retrieving the standard
// designer option service values in design mode.
public ref class IDesignerOptionServiceControl: public System::Windows::Forms::UserControl
{
private:
IDesignerOptionService^ designerOptionService;
public:
IDesignerOptionServiceControl()
{
this->BackColor = Color::Beige;
this->Size = System::Drawing::Size( 404, 135 );
}
property System::ComponentModel::ISite^ Site
{
virtual System::ComponentModel::ISite^ get() override
{
return __super::Site;
}
virtual void set( System::ComponentModel::ISite^ value ) override
{
__super::Site = value;
// If siting component, attempt to obtain an IDesignerOptionService.
if ( __super::Site != nullptr )
designerOptionService = dynamic_cast<IDesignerOptionService^>(this->GetService( IDesignerOptionService::typeid ));
}
}
protected:
// Displays control information and current IDesignerOptionService
// values, if available.
virtual void OnPaint( System::Windows::Forms::PaintEventArgs^ e ) override
{
e->Graphics->DrawString( "IDesignerOptionServiceControl", gcnew System::Drawing::Font( "Arial",9 ), gcnew SolidBrush( Color::Blue ), 4, 4 );
if ( this->DesignMode )
e->Graphics->DrawString( "Currently in design mode", gcnew System::Drawing::Font( "Arial",8 ), gcnew SolidBrush( Color::Black ), 4, 18 );
else
e->Graphics->DrawString( "Not in design mode. Cannot access IDesignerOptionService.", gcnew System::Drawing::Font( "Arial",8 ), gcnew SolidBrush( Color::Red ), 4, 18 );
if ( __super::Site != nullptr && designerOptionService != nullptr )
{
e->Graphics->DrawString( "IDesignerOptionService provides access to the table of option values listed when", gcnew System::Drawing::Font( "Arial",8 ), gcnew SolidBrush( Color::Black ), 4, 38 );
e->Graphics->DrawString( "the Windows Forms Designer\\General tab of the Tools\\Options menu is selected.", gcnew System::Drawing::Font( "Arial",8 ), gcnew SolidBrush( Color::Black ), 4, 50 );
e->Graphics->DrawString( "Table of standard value names and current values", gcnew System::Drawing::Font( "Arial",8 ), gcnew 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.
System::Drawing::Size size = *dynamic_cast<System::Drawing::Size^>(designerOptionService->GetOptionValue( "WindowsFormsDesigner\\General", "GridSize" ));
e->Graphics->DrawString( "GridSize", gcnew System::Drawing::Font( "Arial",8 ), gcnew SolidBrush( Color::Black ), 4, (float)ypos );
e->Graphics->DrawString( size.ToString(), gcnew System::Drawing::Font( "Arial",8 ), gcnew SolidBrush( Color::Black ), 100, (float)ypos );
ypos += 12;
// Obtains and shows whether the design mode surface grid is enabled.
bool showGrid = *dynamic_cast<bool^>(designerOptionService->GetOptionValue( "WindowsFormsDesigner\\General", "ShowGrid" ));
e->Graphics->DrawString( "ShowGrid", gcnew System::Drawing::Font( "Arial",8 ), gcnew SolidBrush( Color::Black ), 4, (float)ypos );
e->Graphics->DrawString( showGrid.ToString(), gcnew System::Drawing::Font( "Arial",8 ), gcnew SolidBrush( Color::Black ), 100, (float)ypos );
ypos += 12;
// Obtains and shows whether components should be aligned with the surface grid.
bool snapToGrid = *dynamic_cast<bool^>(designerOptionService->GetOptionValue( "WindowsFormsDesigner\\General", "SnapToGrid" ));
e->Graphics->DrawString( "SnapToGrid", gcnew System::Drawing::Font( "Arial",8 ), gcnew SolidBrush( Color::Black ), 4, (float)ypos );
e->Graphics->DrawString( snapToGrid.ToString(), gcnew System::Drawing::Font( "Arial",8 ), gcnew SolidBrush( Color::Black ), 100, (float)ypos );
}
}
};
}
package IDesignerOptionServiceExample;
import System.*;
import System.Collections.*;
import System.ComponentModel.*;
import System.ComponentModel.Design.*;
import System.Drawing.*;
import System.Data.*;
import System.Windows.Forms.*;
import System.Windows.Forms.Design.*;
// This control demonstrates retrieving the standard
// designer option service values in design mode.
public class IDesignerOptionServiceControl extends
System.Windows.Forms.UserControl
{
private IDesignerOptionService designerOptionService;
public IDesignerOptionServiceControl()
{
this.set_BackColor(Color.get_Beige());
this.set_Size(new Size(404, 135));
} //IDesignerOptionServiceControl
/** @property
*/
public System.ComponentModel.ISite get_Site()
{
return super.get_Site();
} //get_Site
/** @property
*/
public void set_Site(System.ComponentModel.ISite value)
{
super.set_Site(value);
// If siting component, attempt to obtain an IDesignerOptionService.
if (super.get_Site() != null) {
designerOptionService = ((IDesignerOptionService)
(this.GetService(IDesignerOptionService.class.ToType())));
}
} //set_Site
// Displays control information and current IDesignerOptionService
// values, if available.
protected void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
e.get_Graphics().DrawString("IDesignerOptionServiceControl", new
Font("Arial", 9), new SolidBrush(Color.get_Blue()), 4, 4);
if (this.get_DesignMode()) {
e.get_Graphics().DrawString("Currently in design mode",
new Font("Arial", 8), new SolidBrush(Color.get_Black()), 4, 18);
}
else {
e.get_Graphics().DrawString("Not in design mode. Cannot access"
+ " IDesignerOptionService.", new Font("Arial", 8),
new SolidBrush(Color.get_Red()), 4, 18);
}
if (super.get_Site() != null && designerOptionService != null) {
e.get_Graphics().DrawString("IDesignerOptionService provides "
+ " access to the table of option values listed when",
new Font("Arial", 8), new SolidBrush(Color.get_Black()),4,38);
e.get_Graphics().DrawString("the Windows Forms Designer\\General"
+ " tab of the Tools\\Options menu is selected.",
new Font("Arial", 8), new SolidBrush(Color.get_Black()), 4, 50);
e.get_Graphics().DrawString("Table of standard value names and "
+ " current values", new Font("Arial", 8), new SolidBrush(
Color.get_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.
Size size = ((Size)(designerOptionService.GetOptionValue(
"WindowsFormsDesigner\\General", "GridSize")));
e.get_Graphics().DrawString("GridSize", new Font("Arial", 8),
new SolidBrush(Color.get_Black()), 4, ypos);
e.get_Graphics().DrawString(size.ToString(), new Font("Arial", 8),
new SolidBrush(Color.get_Black()), 100, ypos);
ypos += 12;
// Obtains and shows whether the design mode surface
// grid is enabled.
boolean showGrid = (System.Convert.ToBoolean((designerOptionService.
GetOptionValue("WindowsFormsDesigner\\General", "ShowGrid"))));
e.get_Graphics().DrawString("ShowGrid", new Font("Arial", 8),
new SolidBrush(Color.get_Black()), 4, ypos);
e.get_Graphics().DrawString(System.Convert.ToString(showGrid),
new Font("Arial", 8), new SolidBrush(Color.get_Black()),
100, ypos);
ypos += 12;
// Obtains and shows whether components should be aligned with the
// surface grid.
boolean snapToGrid = System.Convert.ToBoolean(
(designerOptionService.GetOptionValue(
"WindowsFormsDesigner\\General", "SnapToGrid")));
e.get_Graphics().DrawString("SnapToGrid", new Font("Arial", 8),
new SolidBrush(Color.get_Black()), 4, ypos);
e.get_Graphics().DrawString(System.Convert.ToString(snapToGrid),
new Font("Arial", 8), new SolidBrush(Color.get_Black()),
100, ypos);
}
} //OnPaint
} //IDesignerOptionServiceControl
Plattformen
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
Siehe auch
Referenz
IDesignerOptionService-Member
System.ComponentModel.Design-Namespace
IDesigner-Schnittstelle
DesignerOptionService-Klasse