Condividi tramite


MailFileEditor Classe

Definizione

Fornisce un'interfaccia utente per la selezione e la modifica di un nome file di posta elettronica per una proprietà in fase di progettazione.

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
Ereditarietà
MailFileEditor

Esempio

Nell'esempio di codice seguente viene illustrato come associare un'istanza della MailFileEditor classe a una proprietà contenuta in un controllo personalizzato. Quando la proprietà del controllo viene modificata nell'area di progettazione, la MailFileEditor classe fornisce l'interfaccia utente per selezionare e modificare un nome file di posta elettronica per il valore della proprietà.

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

Commenti

La MailFileEditor classe è un UITypeEditor oggetto che può essere utilizzato in fase di progettazione per selezionare e modificare un nome di file di posta elettronica come stringa e assegnare la stringa a una proprietà del controllo. Ad esempio, il EmbeddedMailObject controllo usa la MailFileEditor classe in fase di progettazione per impostare il valore della Path proprietà .

Utilizzare l'attributo per associare l'oggetto EditorAttributeMailFileEditor a una proprietà . Quando la proprietà associata viene modificata nell'area di progettazione, l'host della finestra di progettazione chiama il EditValue metodo . Il EditValue metodo visualizza una finestra di dialogo per la selezione di un nome file di posta da un elenco filtrato di file e restituisce il nome file selezionato dall'utente. Il GetEditStyle metodo indica lo stile di visualizzazione dell'interfaccia utente.

Derivare una classe da MailFileEditor per definire un editor personalizzato per una proprietà del nome file di posta elettronica. Ad esempio, una classe derivata può eseguire l'override del EditValue metodo e visualizzare un'istanza OpenFileDialog con un filtro o un titolo del file di posta elettronica personalizzato.

Costruttori

Nome Descrizione
MailFileEditor()

Inizializza una nuova istanza della classe MailFileEditor.

Proprietà

Nome Descrizione
Caption

Ottiene la didascalia per la finestra di dialogo dell'editor.

Filter

Ottiene la stringa di filtro file per la finestra di dialogo, ad esempio "*.txt").

IsDropDownResizable

Ottiene un valore che indica se gli editor a discesa devono essere ridimensionati dall'utente.

(Ereditato da UITypeEditor)
Options

Ottiene le opzioni da usare per il generatore di URL.

(Ereditato da UrlEditor)

Metodi

Nome Descrizione
EditValue(IServiceProvider, Object)

Modifica il valore dell'oggetto specificato utilizzando lo stile dell'editor indicato dal GetEditStyle() metodo .

(Ereditato da UITypeEditor)
EditValue(ITypeDescriptorContext, IServiceProvider, Object)

Modifica il valore dell'oggetto specificato utilizzando lo stile dell'editor fornito dal GetEditStyle(ITypeDescriptorContext) metodo .

(Ereditato da UrlEditor)
Equals(Object)

Determina se l'oggetto specificato è uguale all'oggetto corrente.

(Ereditato da Object)
GetEditStyle()

Ottiene lo stile dell'editor utilizzato dal EditValue(IServiceProvider, Object) metodo .

(Ereditato da UITypeEditor)
GetEditStyle(ITypeDescriptorContext)

Ottiene lo stile di modifica del EditValue(ITypeDescriptorContext, IServiceProvider, Object) metodo .

(Ereditato da UrlEditor)
GetHashCode()

Funge da funzione hash predefinita.

(Ereditato da Object)
GetPaintValueSupported()

Indica se questo editor supporta il disegno di una rappresentazione del valore di un oggetto.

(Ereditato da UITypeEditor)
GetPaintValueSupported(ITypeDescriptorContext)

Indica se il contesto specificato supporta il disegno di una rappresentazione del valore di un oggetto all'interno del contesto specificato.

(Ereditato da UITypeEditor)
GetType()

Ottiene il Type dell'istanza corrente.

(Ereditato da Object)
MemberwiseClone()

Crea una copia superficiale del Objectcorrente.

(Ereditato da Object)
PaintValue(Object, Graphics, Rectangle)

Disegna una rappresentazione del valore dell'oggetto specificato nell'area di disegno specificata.

(Ereditato da UITypeEditor)
PaintValue(PaintValueEventArgs)

Disegna una rappresentazione del valore di un oggetto utilizzando l'oggetto specificato PaintValueEventArgs.

(Ereditato da UITypeEditor)
ToString()

Restituisce una stringa che rappresenta l'oggetto corrente.

(Ereditato da Object)

Si applica a

Vedi anche