ControlDesigner.Initialize(IComponent) Yöntem

Tanım

Denetim tasarımcısını başlatır ve belirtilen bileşeni yükler.

C#
public override void Initialize(System.ComponentModel.IComponent component);

Parametreler

component
IComponent

Tasarlanan denetim.

Örnekler

Aşağıdaki kod örneği, iç değişkenleri başlatmak için yöntemini geçersiz kılan Initialize bir denetim sınıfı ve denetim tasarımcısı sınıfının nasıl kullanılacağını gösterir.

C#
using System;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.Design;
using System.Web.UI.WebControls;

namespace AspNet.Samples
{
    // Create a custom class to render the Text property
    [Designer(typeof(SimpleDesigner)), DefaultProperty("Text"), 
    ToolboxData("<{0}:Simple runat=\"server\"></{0}:Simple>")]
    public sealed class Simple : WebControl
    {
        public Simple()
        { }

        // Create a Text property
        [Browsable(true), Bindable(true), 
            PersistenceMode(PersistenceMode.Attribute)]
        public string Text
        {
            get
            {
                object o = ViewState["TextProp"];
                return (o == null) ? "Sample Text" : (string)o;
            }
            set { ViewState["TextProp"] = value; }
        }

        // Render the text inside the control
        protected override void RenderContents(HtmlTextWriter writer)
        {
            writer.Write(Text);
        }
    }
}

namespace AspNet.Samples
{
    //Create a designer class for the Simple control
    public sealed class SimpleDesigner : ControlDesigner
    {
        // Declare a reference to the Simple class
        private Simple simpleControl;

        public SimpleDesigner()
        { }

        public override void Initialize(IComponent ponent)
        {
            base.Initialize(ponent);

            // Get a reference to the control
            simpleControl = (Simple)ponent;

            //Set Text to the control's ID
            simpleControl.Text = simpleControl.ID;
        }

        // Allow resizing the control in the design host
        public override bool AllowResize
        {
            get
            {
                return true;
            }
        }

        public override string GetDesignTimeHtml()
        {
            if (simpleControl.Text.Length > 0)
            {
                string spec = "<a href='{0}.aspx'>{0}</a>";
                return String.Format(spec, simpleControl.Text);
            }
            else
            {
                return GetEmptyDesignTimeHtml();
            }
        }
    }
}

Açıklamalar

Yöntemi Initialize , aşağıdaki eylemleri tamamlamak için tasarım konağı tarafından çağrılır:

  • Denetim tasarımcısını tasarım bileşeniyle birlikte yükleyin.

  • yöntemini kullanarak SetViewFlags denetimde görünümü ayarlayın.

  • İlişkili denetimin doğru türde olduğunu doğrulayın.

Şunlara uygulanır

Ürün Sürümler
.NET Framework 1.1, 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

Ayrıca bkz.