.NET Framework Class Library  

IDesignerOptionService Interface

Provides access to the designer options located on the Tools menu under the Options menu item in the Visual Studio .NET environment.

For a list of all members of this type, see IDesignerOptionService Members.

[Visual Basic]
Public Interface IDesignerOptionService
[C#]
public interface IDesignerOptionService
[C++]
public __gc __interface IDesignerOptionService
[JScript]
public interface IDesignerOptionService

Remarks

IDesignerOptionService provides an interface that can be used to retrieve and update the values of the Windows Form Designer options. The GetOptionValue method retrieves the value of the option indicated by the page and value names. The SetOptionValue method sets a specified value for an option on the indicated page name matching the indicated value name.

Note   The page and value names are always expected in English. Therefore, the following table is provided to help you access the options you want.

The page name is a concatenation of the Windows Forms Designer options category name and the page name, which is typically General. Therefore, you can usually access the designer options page with the English page name "Windows Forms Designer\General".

The following table indicates the English value names, their data format, and a description of each:

Value Name Value Format Description
"GridSize" Size(x,y) The size of each grid square.
"GridSize.Width" integer The width of each grid square. This nested property is read-only when accessed through the designer option service.
"GridSize.Height" integer The height of each grid square. This nested property is read-only when accessed through the designer option service.
"ShowGrid" Boolean true if the grid should be shown; false if the grid should not be shown.
"SnapToGrid" Boolean true if the positions of the components should be aligned to the grid; false if the positions should not necessarily be aligned.

Example

[Visual Basic] 
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.
    <System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _
    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

[C#] 
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.
        [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")] 
        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);                
            }
        }
    }
}

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.ComponentModel.Design

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System (in System.dll)

See Also

IDesignerOptionService Members | System.ComponentModel.Design Namespace | IDesigner