MdbDataFileEditor 類別

定義

提供設計階段的使用者介面,以選取 Microsoft Access 資料庫檔案。

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

範例

下列程式碼範例示範如何將 類別的 MdbDataFileEditor 實例與自訂控制項中包含的屬性產生關聯。 當您在設計介面上編輯控制項屬性時,類別 MdbDataFileEditor 會提供使用者介面來選取和編輯屬性值的 Access 資料庫檔案名。

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 MDB data file name property.  Indicate that the
        // property can be edited at design-time with the MdbDataFileEditor class.
        [EditorAttribute(typeof(System.Web.UI.Design.MdbDataFileEditor), 
                         typeof(System.Drawing.Design.UITypeEditor))]
        public string MdbFileName
        {
            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 MDB data file name property.  Indicate that the
        ' property can be edited at design-time with the MdbDataFileEditor class.
        <EditorAttribute(GetType(System.Web.UI.Design.MdbDataFileEditor), _
                         GetType(System.Drawing.Design.UITypeEditor))> _
        Public Property MdbFileName() 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

備註

MdbDataFileEditor物件是在設計階段用來選取和編輯 Microsoft Access 資料庫檔案的 URL (.mdb) ,然後將 URL 指派給控制項屬性。 例如,控制項在 AccessDataSource 設計階段使用 MdbDataFileEditor 類別來設定 屬性的值 DataFile

EditorAttribute使用 屬性將 與 屬性產生關聯 MdbDataFileEditor 。 在設計介面上編輯相關聯的屬性時,設計工具主機會呼叫 EditValue 方法。 方法 EditValueBuildUrl 使用 方法,接著顯示使用者介面以選取 URL,然後傳回使用者選取的 URL。 方法 GetEditStyle 表示使用者介面的顯示樣式。

MdbDataFileEditor 衍生類別,以定義 Access 資料庫 URL 屬性的自訂編輯器。 例如,衍生類別可以覆寫 EditValue 方法,然後使用自訂 FilterCaption 值呼叫 BuildUrl 方法。

建構函式

MdbDataFileEditor()

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

屬性

Caption

取得要在選取對話方塊上顯示的標題。

Filter

取得編輯器的 URL 篩選選項,用來篩選要顯示在 URL 選取對話方塊中的項目。

IsDropDownResizable

取得值,表示使用者是否能夠調整下拉式編輯器的大小。

(繼承來源 UITypeEditor)
Options

取得 URL 產生器 (Builder) 使用的選項。

(繼承來源 UrlEditor)

方法

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)

適用於

另請參閱