MdbDataFileEditor Classe

Definição

Fornece uma interface de utilizador em tempo de design para selecionar um ficheiro de base de dados 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
Herança
MdbDataFileEditor

Exemplos

O exemplo de código seguinte demonstra como associar uma instância da MdbDataFileEditor classe a uma propriedade contida num controlo personalizado. Quando edita a propriedade de controlo na superfície de design, a MdbDataFileEditor classe fornece a interface de utilizador para selecionar e editar um nome de ficheiro de base de dados Access para o valor da propriedade.

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

Observações

Um objeto MdbDataFileEditor é usado no momento do design para selecionar e editar uma URL para um ficheiro de base de dados Microsoft Access (.mdb), e depois atribuir a URL a uma propriedade de controlo. Por exemplo, o AccessDataSource controlo usa a MdbDataFileEditor classe em tempo de projeto para definir o valor da DataFile propriedade.

Use o EditorAttribute atributo para associar o MdbDataFileEditor a uma propriedade. Quando a propriedade associada é editada na superfície de design, o hospedeiro designer chama o EditValue método. O EditValue método utiliza o BuildUrl método, que por sua vez exibe uma interface de utilizador para selecionar o URL, e depois devolve o URL selecionado pelo utilizador. O GetEditStyle método indica o estilo de apresentação da interface de utilizador.

Derive uma classe a partir de MdbDataFileEditor para definir um editor personalizado para uma propriedade URL da base de dados Access. Por exemplo, uma classe derivada pode sobrescrever o EditValue método e depois chamá-lo BuildUrl com um custom Filter ou Caption valor.

Construtores

Name Description
MdbDataFileEditor()

Inicializa uma nova instância da MdbDataFileEditor classe.

Propriedades

Name Description
Caption

Faz com que a legenda apareça na caixa de diálogo de seleção.

Filter

Obtém as opções de filtro de URL para o editor, que são usadas para filtrar os itens que aparecem na caixa de diálogo de seleção de URL.

IsDropDownResizable

Recebe um valor que indica se os editores de menu suspenso devem ser redimensionáveis pelo utilizador.

(Herdado de UITypeEditor)
Options

Obtém as opções para o criador de URLs usar.

(Herdado de UrlEditor)

Métodos

Name Description
EditValue(IServiceProvider, Object)

Edita o valor do objeto especificado usando o estilo de editor indicado pelo GetEditStyle() método.

(Herdado de UITypeEditor)
EditValue(ITypeDescriptorContext, IServiceProvider, Object)

Edita o valor do objeto especificado usando o estilo editor fornecido pelo GetEditStyle(ITypeDescriptorContext) método.

(Herdado de UrlEditor)
Equals(Object)

Determina se o objeto especificado é igual ao objeto atual.

(Herdado de Object)
GetEditStyle()

Obtém o estilo editor usado pelo EditValue(IServiceProvider, Object) método.

(Herdado de UITypeEditor)
GetEditStyle(ITypeDescriptorContext)

Percebe o estilo de edição do EditValue(ITypeDescriptorContext, IServiceProvider, Object) método.

(Herdado de UrlEditor)
GetHashCode()

Serve como função de hash predefinida.

(Herdado de Object)
GetPaintValueSupported()

Indica se este editor suporta a pintura de uma representação do valor de um objeto.

(Herdado de UITypeEditor)
GetPaintValueSupported(ITypeDescriptorContext)

Indica se o contexto especificado suporta a pintura de uma representação do valor de um objeto dentro do contexto especificado.

(Herdado de UITypeEditor)
GetType()

Obtém o Type da instância atual.

(Herdado de Object)
MemberwiseClone()

Cria uma cópia superficial do atual Object.

(Herdado de Object)
PaintValue(Object, Graphics, Rectangle)

Pinta uma representação do valor do objeto especificado na tela especificada.

(Herdado de UITypeEditor)
PaintValue(PaintValueEventArgs)

Pinta uma representação do valor de um objeto usando o especificado PaintValueEventArgs.

(Herdado de UITypeEditor)
ToString()

Devolve uma cadeia que representa o objeto atual.

(Herdado de Object)

Aplica-se a

Ver também