İngilizce dilinde oku

Aracılığıyla paylaş


DesignerOptionService Sınıf

Tanım

Tasarımcı için seçenek değerlerini almak ve ayarlamak için bir temel sınıf sağlar.

C#
public abstract class DesignerOptionService : System.ComponentModel.Design.IDesignerOptionService
Devralma
DesignerOptionService
Türetilmiş
Uygulamalar

Örnekler

Aşağıdaki kod örneği, standart seçeneklerin geçerli değerlerini görüntülemek için öğesine erişmeyi DesignerOptionService gösterir.

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

Açıklamalar

DesignerOptionService sınıfı bir seçenek koleksiyonu sağlar. Bu seçenek koleksiyonlarının her biri, daha fazla filtrelenmesine olanak tanıyan bir dizin oluşturucuya sahiptir. Her seçenek koleksiyonu kendi seçenek kümesinin yanı sıra tüm alt seçeneklerinin bir toplamasını içerir. Özellikler arasında adlandırma çakışması olması durumunda, en dıştaki seçenekler nesnesi önceliklidir. Aşağıdaki Araçlar | Seçenekler kullanıcı arabirimi (UI) yapısı, en dıştaki seçenekler nesnesinin nasıl daha önemli olduğunu gösterir:

WindowsFormsDesigner | Genel

  • SnapToGrid

  • ShowGrid

  • Gridsize

adlı servicebir IDesignerOptionService değer verilip özelliğin GridSize değerine ulaşabilmek için aşağıdaki çağrıyı yapabilirsiniz:

C#
// Obtains and shows the size of the standard design-mode grid square.
Size size = (Size)designerOptionService.GetOptionValue("WindowsFormsDesigner\\General", "GridSize");

Bu, başka bir sayfaya geçmek GridSize isteyene kadar çalışır. Ayrıca, IDesignerOptionService bulma mekanizması sağlamaz. Hangi dizeyi geçireceğinizi bilmiyorsanız, hizmet özellik değerini bulamaz.

DesignerOptionService sınıfı bu sorunları giderir. Koleksiyonları sorgulayabilirsiniz ve nesnede DesignerOptionService.DesignerOptionCollection tanımlanan ve koleksiyonu genişletilebilir olarak işaretleyen bir tür dönüştürücüsü vardır. Bu tür dönüştürücü ile tasarımcı seçeneği hizmetinin tamamını bir özellik penceresine geçirebilir ve hizmeti görsel olarak inceleyebilirsiniz.

Oluşturucular

DesignerOptionService()

DesignerOptionService sınıfının yeni bir örneğini başlatır.

Özellikler

Options

Bu hizmet için seçenekler koleksiyonunu alır.

Yöntemler

CreateOptionCollection(DesignerOptionService+DesignerOptionCollection, String, Object)

Verilen adla yeni DesignerOptionService.DesignerOptionCollection bir oluşturur ve bunu verilen üst öğeye ekler.

Equals(Object)

Belirtilen nesnenin geçerli nesneye eşit olup olmadığını belirler.

(Devralındığı yer: Object)
GetHashCode()

Varsayılan karma işlevi işlevi görür.

(Devralındığı yer: Object)
GetType()

Type Geçerli örneğini alır.

(Devralındığı yer: Object)
MemberwiseClone()

Geçerli Objectöğesinin sığ bir kopyasını oluşturur.

(Devralındığı yer: Object)
PopulateOptionCollection(DesignerOptionService+DesignerOptionCollection)

bir DesignerOptionService.DesignerOptionCollectiondoldurur.

ShowDialog(DesignerOptionService+DesignerOptionCollection, Object)

Verilen nesnenin seçenekler iletişim kutusunu gösterir.

ToString()

Geçerli nesneyi temsil eden dizeyi döndürür.

(Devralındığı yer: Object)

Belirtik Arabirim Kullanımları

IDesignerOptionService.GetOptionValue(String, String)

Bu pakette tanımlanan bir seçeneğin değerini alır.

IDesignerOptionService.SetOptionValue(String, String, Object)

Bu pakette tanımlanan bir seçeneğin değerini ayarlar.

Şunlara uygulanır

Ürün Sürümler
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

Ayrıca bkz.