Share via


MailFileEditor Classe

Definizione

Fornisce un'interfaccia utente per la selezione e la modifica del nome di un file della posta 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 di 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 usato in fase di progettazione per selezionare e modificare un nome di file di posta elettronica come stringa e assegnare la stringa a una proprietà di controllo. Ad esempio, il EmbeddedMailObject controllo usa la MailFileEditor classe in fase di progettazione per impostare il valore della Path proprietà.

Usare l'attributo per associare l'oggetto EditorAttribute MailFileEditor 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 selezionare un nome file di posta da un elenco filtrato di file e restituisce il nome del file selezionato dall'utente. Il GetEditStyle metodo indica lo stile di visualizzazione dell'interfaccia utente.

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

Costruttori

MailFileEditor()

Inizializza una nuova istanza della classe MailFileEditor.

Proprietà

Caption

Ottiene la didascalia della finestra di dialogo dell'editor.

Filter

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

IsDropDownResizable

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

(Ereditato da UITypeEditor)
Options

Ottiene le opzioni utilizzabili dal generatore di URL.

(Ereditato da UrlEditor)

Metodi

EditValue(IServiceProvider, Object)

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

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

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

(Ereditato da UrlEditor)
Equals(Object)

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

(Ereditato da Object)
GetEditStyle()

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

(Ereditato da UITypeEditor)
GetEditStyle(ITypeDescriptorContext)

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

(Ereditato da UrlEditor)
GetHashCode()

Funge da funzione hash predefinita.

(Ereditato da Object)
GetPaintValueSupported()

Indica se questo editor supporta la rappresentazione grafica del valore di un oggetto.

(Ereditato da UITypeEditor)
GetPaintValueSupported(ITypeDescriptorContext)

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

(Ereditato da UITypeEditor)
GetType()

Ottiene l'oggetto Type dell'istanza corrente.

(Ereditato da Object)
MemberwiseClone()

Crea una copia superficiale dell'oggetto Object corrente.

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

Descrive graficamente il valore dell'oggetto specificato sulla superficie specificata.

(Ereditato da UITypeEditor)
PaintValue(PaintValueEventArgs)

Descrive graficamente il valore di un oggetto usando la classe PaintValueEventArgs specificata.

(Ereditato da UITypeEditor)
ToString()

Restituisce una stringa che rappresenta l'oggetto corrente.

(Ereditato da Object)

Si applica a

Vedi anche