MailFileEditor Classe

Definição

Fornece uma interface de utilizador para selecionar e editar o nome de um ficheiro de email para uma propriedade no momento do projeto.

public ref class MailFileEditor : System::Web::UI::Design::UrlEditor
public class MailFileEditor : System.Web.UI.Design.UrlEditor
type MailFileEditor = class
    inherit UrlEditor
Public Class MailFileEditor
Inherits UrlEditor
Herança
MailFileEditor

Exemplos

O exemplo de código seguinte demonstra como associar uma instância da MailFileEditor classe a uma propriedade contida num controlo personalizado. Quando a propriedade de controlo é editada na superfície de design, a MailFileEditor classe fornece a interface do utilizador para selecionar e editar o nome de um ficheiro de email 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;

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 file name property.  Indicate that the
        // property can be edited at design-time with the MailFileEditor class.
        [EditorAttribute(typeof(System.Web.UI.Design.MailFileEditor), 
                         typeof(System.Drawing.Design.UITypeEditor))]
        public string MailFileName
        {
            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 (System.IO.File.Exists(_filename))
                    {
                        DateTime lastChangedStamp = System.IO.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

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 mail file name property.  Indicate that the
        ' property can be edited at design-time with the MailFileEditor class.
        <EditorAttribute(GetType(System.Web.UI.Design.MailFileEditor), _
                         GetType(System.Drawing.Design.UITypeEditor))> _
        Public Property MailFileName() 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 System.IO.File.Exists(_filename) Then
                        Dim lastChangedStamp As DateTime
                        lastChangedStamp = System.IO.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

A MailFileEditor classe é um UITypeEditor objeto que pode ser usado no momento do design para selecionar e editar um nome de ficheiro de e-mail como uma cadeia, e atribuir a cadeia a uma propriedade de controlo. Por exemplo, o EmbeddedMailObject controlo usa a MailFileEditor classe em tempo de projeto para definir o valor da Path propriedade.

Use o EditorAttribute atributo para associar o MailFileEditor a uma propriedade. Quando a propriedade associada é editada na superfície de design, o host designer chama o EditValue método. O EditValue método apresenta uma caixa de diálogo para selecionar um nome de ficheiro de email a partir de uma lista filtrada de ficheiros, e devolve o nome do ficheiro selecionado pelo utilizador. O GetEditStyle método indica o estilo de apresentação da interface de utilizador.

Derive uma classe de para MailFileEditor definir um editor personalizado para uma propriedade de nome de ficheiro de e-mail. Por exemplo, uma classe derivada pode sobrepor o EditValue método e mostrar uma OpenFileDialog instância com um filtro ou título personalizado de ficheiro de email.

Construtores

Name Description
MailFileEditor()

Inicializa uma nova instância da MailFileEditor classe.

Propriedades

Name Description
Caption

Recebe a legenda para o diálogo do editor.

Filter

Obtém a cadeia de filtro do ficheiro para o diálogo (como "*.txt").

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