This documentation is archived and is not being maintained.

IDesignerOptionService Interface

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

Namespace:  System.ComponentModel.Design
Assembly:  System (in System.dll)

public interface class IDesignerOptionService

The IDesignerOptionService type exposes the following members.

  NameDescription
Public methodGetOptionValueGets the value of the specified Windows Forms Designer option.
Public methodSetOptionValueSets the value of the specified Windows Forms Designer option.
Top

IDesignerOptionService provides an interface that can be used to retrieve and update the values of the Windows Forms Designer options, which are listed within the dialog displayed by the Options command of the Tools menu of the Visual Studio development environment. The GetOptionValue method retrieves the value of a specified option. The SetOptionValue method sets a specified value for a specified option.

The following code example demonstrates accessing the IDesignerOptionService to display the current values of the standard options.


#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 );
         }
      }
   };
}


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Show: