Compartilhar via


MailFileEditor Classe

Definição

Fornece uma interface do usuário para selecionar e editar um nome de arquivo de email para uma propriedade em tempo de design.

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 a seguir demonstra como associar uma instância da classe a MailFileEditor uma propriedade contida em um controle personalizado. Quando a propriedade de controle é editada na superfície de design, a MailFileEditor classe fornece a interface do usuário para selecionar e editar um nome de arquivo 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

Comentários

A MailFileEditor classe é um UITypeEditor objeto que pode ser usado em tempo de design para selecionar e editar um nome de arquivo de email como uma cadeia de caracteres e atribuir a cadeia de caracteres a uma propriedade de controle. Por exemplo, o EmbeddedMailObject controle usa a MailFileEditor classe em tempo de design para definir o valor da Path propriedade.

Use o EditorAttribute atributo para associar a MailFileEditor uma propriedade. Quando a propriedade associada é editada na superfície de design, o host do designer chama o EditValue método. O EditValue método exibe uma caixa de diálogo para selecionar um nome de arquivo de email em uma lista filtrada de arquivos e retorna o nome do arquivo selecionado pelo usuário. O GetEditStyle método indica o estilo de exibição da interface do usuário.

Derivar uma classe do MailFileEditor editor personalizado para uma propriedade de nome de arquivo de email. Por exemplo, uma classe derivada pode substituir o EditValue método e exibir uma OpenFileDialog instância com um filtro ou título de arquivo de email personalizado.

Construtores

Nome Description
MailFileEditor()

Inicializa uma nova instância da classe MailFileEditor.

Propriedades

Nome Description
Caption

Obtém a legenda da caixa de diálogo do editor.

Filter

Obtém a cadeia de caracteres de filtro de arquivo para a caixa de diálogo (como "*.txt").

IsDropDownResizable

Obtém um valor que indica se os editores suspensos devem ser redimensionáveis pelo usuário.

(Herdado de UITypeEditor)
Options

Obtém as opções para o construtor de URL usar.

(Herdado de UrlEditor)

Métodos

Nome Description
EditValue(IServiceProvider, Object)

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

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

Edita o valor do objeto especificado usando o estilo do 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 do editor usado pelo EditValue(IServiceProvider, Object) método.

(Herdado de UITypeEditor)
GetEditStyle(ITypeDescriptorContext)

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

(Herdado de UrlEditor)
GetHashCode()

Serve como a função de hash padrão.

(Herdado de Object)
GetPaintValueSupported()

Indica se esse editor dá suporte à pintura de uma representação do valor de um objeto.

(Herdado de UITypeEditor)
GetPaintValueSupported(ITypeDescriptorContext)

Indica se o contexto especificado dá suporte à 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 Objectatual.

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

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

(Herdado de UITypeEditor)
PaintValue(PaintValueEventArgs)

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

(Herdado de UITypeEditor)
ToString()

Retorna uma cadeia de caracteres que representa o objeto atual.

(Herdado de Object)

Aplica-se a

Confira também