語言

XsdSchemaFileEditor 類別

定義

提供設計時使用者介面,用於選擇 XML 結構定義檔案。

public ref class XsdSchemaFileEditor : System::Web::UI::Design::UrlEditor
public class XsdSchemaFileEditor : System.Web.UI.Design.UrlEditor
type XsdSchemaFileEditor = class
    inherit UrlEditor
Public Class XsdSchemaFileEditor
Inherits UrlEditor
繼承
XsdSchemaFileEditor

範例

以下程式碼範例示範如何將該類別的實例 XsdSchemaFileEditor 與包含在自訂控制項中的屬性關聯起來。 當控制屬性在設計表面被編輯時,類別 XsdSchemaFileEditor 提供使用者介面,讓使用者能選擇並編輯屬性值的 XML 結構定義檔名。

using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Web.UI;
using System.Web.UI.Design;
using System.Web.UI.Design.WebControls;
using System.Web.UI.WebControls;
using System.IO;

namespace ControlDesignerSamples.CS
{
    // Define a simple text control, derived from the 
    // System.Web.UI.WebControls.Label class.
    [
        Designer(typeof(TextControlDesigner))
    ]
    public class SimpleTextControl : Label
    {
        // Define a private member to store the file name value in the control.
        private string _filename = "";
        private string _internalText = "";

        // Define the public XML schema file property.  Indicate that the
        // property can be edited at design-time with the XsdSchemaFileEditor class.
        [EditorAttribute(typeof(System.Web.UI.Design.XsdSchemaFileEditor), 
                         typeof(System.Drawing.Design.UITypeEditor))]
        public string SchemaFileName
        {
            get
            {
                return _filename;
            }
            set
            {
                _filename = value;
            }
        }

        // Define a property that returns the timestamp
        // for the selected file.
        public string LastChanged
        {
            get
            {
                if ((_filename != null) && (_filename.Length > 0))
                {
                    if (File.Exists(_filename))
                    {
                        DateTime lastChangedStamp = File.GetLastWriteTime(_filename);
                        return lastChangedStamp.ToLongDateString();
                    }
                }
                return "";
            }
        }

        // Override the control Text property, setting the default
        // text to the LastChanged string value for the selected
        // file name.  If the file name has not been set in the
        // design view, then default to an empty string.
        public override string Text
        {
            get
            {
                if ((_internalText == "") && (LastChanged.Length > 0))
                {
                    // If the internally stored value hasn't been set,
                    // and the file name property has been set,
                    // return the last changed timestamp for the file.
                    _internalText = LastChanged;
                } 
                return _internalText;
            }

            set
            {
                if ((value != null) && (value.Length > 0))
                {
                    _internalText = value;
                }
                else {
                    _internalText = "";
                }
            }
        }
    }
}

Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Web.UI
Imports System.Web.UI.Design
Imports System.Web.UI.Design.WebControls
Imports System.Web.UI.WebControls
Imports System.IO

Namespace ControlDesignerSamples.VB


    ' Define a simple text control, derived from the 
    ' System.Web.UI.WebControls.Label class.

    <Designer(GetType(TextControlDesigner))> _
    Public Class SimpleTextControl
        Inherits Label

        ' Define a private member to store the file name value in the control.
        Private _filename As String = ""
        Private _internalText As String = ""

        ' Define the public XSD schema file name property.  Indicate that the
        ' property can be edited at design-time with the XsdSchemaFileEditor class.
        <EditorAttribute(GetType(System.Web.UI.Design.XsdSchemaFileEditor), _
                         GetType(System.Drawing.Design.UITypeEditor))> _
        Public Property SchemaFileName() As String
            Get
                Return _filename
            End Get

            Set(ByVal value As String)
                _filename = value
            End Set
        End Property

        ' Define a property that returns the timestamp
        ' for the selected file.
        Public ReadOnly Property LastChanged() As String
            Get
                If Not _filename Is Nothing AndAlso _filename.Length > 0 Then
                    If File.Exists(_filename) Then
                        Dim lastChangedStamp As DateTime
                        lastChangedStamp = File.GetLastWriteTime(_filename)
                        Return lastChangedStamp.ToLongDateString()
                    End If
                End If

                Return String.Empty

            End Get

        End Property

        ' Override the control Text property, setting the default
        ' text to the LastChanged string value for the selected
        ' file name.  If the file name has not been set in the
        ' design view, then default to an empty string.
        Public Overrides Property Text() As String
            Get
                If _internalText.Length = 0 And LastChanged.Length > 0 Then
                    ' If the internally stored value hasn't been set,
                    ' and the file name property has been set,
                    ' return the last changed timestamp for the file.

                    _internalText = LastChanged
                End If
                Return _internalText
            End Get

            Set(ByVal value As String)
                If Not value Is Nothing AndAlso value.Length > 0 Then
                    _internalText = value
                Else
                    _internalText = String.Empty
                End If

            End Set
        End Property

    End Class
End Namespace

備註

XsdSchemaFileEditor在設計時,物件用於選擇並編輯 XML 結構定義檔案(.xsd)的 URL,並將該 URL 指派給控制屬性。

使用屬性 EditorAttribute 來將 與 XsdSchemaFileEditor 屬性關聯。 當相關屬性在設計表面被編輯時,設計主機會呼叫該 EditValue 方法。 該 EditValue 方法使用的方法 BuildUrl ,該方法會顯示一個使用者介面以選擇 URL,然後回傳使用者所選的 URL。 此 GetEditStyle 方法顯示使用者介面的顯示風格。

從中 XsdSchemaFileEditor 衍生一個類別,以定義一個自訂編輯器,以設定一個 XML schema URL 屬性。 例如,導出類別可以覆寫該EditValue方法,然後用自訂BuildUrl值Filter呼叫該Caption方法。

建構函式

名稱 Description
XsdSchemaFileEditor()

初始化 XsdSchemaFileEditor 類別的新執行個體。

屬性

名稱 Description
Caption

讓標題顯示在選擇對話框上。

Filter

取得編輯器的 URL 篩選選項,用來篩選出現在 URL 選擇對話框中的項目。

IsDropDownResizable

會有一個值,指示下拉選單編輯器是否應該被使用者調整大小。

(繼承來源 UITypeEditor)
Options

取得網址建構器可用的選項。

(繼承來源 UrlEditor)

方法

名稱 Description
EditValue(IServiceProvider, Object)

使用方法指示 GetEditStyle() 的編輯器樣式編輯指定物件的值。

(繼承來源 UITypeEditor)
EditValue(ITypeDescriptorContext, IServiceProvider, Object)

使用方法提供的 GetEditStyle(ITypeDescriptorContext) 編輯器樣式編輯指定物件的值。

(繼承來源 UrlEditor)
Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetEditStyle()

會得到方法中使用的 EditValue(IServiceProvider, Object) 編輯器風格。

(繼承來源 UITypeEditor)
GetEditStyle(ITypeDescriptorContext)

能掌握剪輯方法的 EditValue(ITypeDescriptorContext, IServiceProvider, Object) 風格。

(繼承來源 UrlEditor)
GetHashCode()

做為預設哈希函式。

(繼承來源 Object)
GetPaintValueSupported()

表示此編輯器是否支援繪製物件價值的表示。

(繼承來源 UITypeEditor)
GetPaintValueSupported(ITypeDescriptorContext)

表示指定的上下文是否支持在指定上下文中繪製物件價值的表示。

(繼承來源 UITypeEditor)
GetType()

取得目前實例的 Type。

(繼承來源 Object)
MemberwiseClone()

建立目前 Object的淺層複本。

(繼承來源 Object)
PaintValue(Object, Graphics, Rectangle)

繪製指定物件價值在指定畫布上的表示。

(繼承來源 UITypeEditor)
PaintValue(PaintValueEventArgs)

使用指定的 PaintValueEventArgs繪製物件值的表示。

(繼承來源 UITypeEditor)
ToString()

傳回表示目前 物件的字串。

(繼承來源 Object)

適用於

另請參閱