MailFileEditor 类

定义

提供可用于在设计时选择和编辑属性的邮件文件名的用户界面。

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
继承
MailFileEditor

示例

下面的代码示例演示如何将类的 MailFileEditor 实例与包含在自定义控件中的属性相关联。 在设计图面中编辑控件属性时,该 MailFileEditor 类提供用户界面来选择和编辑属性值的邮件文件名。

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

注解

MailFileEditor 类是一个 UITypeEditor 对象,可用于在设计时选择和编辑邮件文件名作为字符串,并将字符串分配给控件属性。 例如,控件 EmbeddedMailObject 在设计时使用 MailFileEditor 类来设置属性的值 Path

使用 EditorAttribute 属性将属性与属性相关联 MailFileEditor 。 在设计图面中编辑关联的属性时,设计器主机将调用该方法 EditValue 。 该方法 EditValue 显示一个对话框,用于从筛选的文件列表中选择邮件文件名,并返回用户选择的文件名。 该方法 GetEditStyle 指示用户界面的显示样式。

MailFileEditor 中派生类以定义邮件文件名属性的自定义编辑器。 例如,派生类可以重写 EditValue 该方法,并使用自定义邮件文件筛选器或标题显示 OpenFileDialog 实例。

构造函数

MailFileEditor()

初始化 MailFileEditor 类的新实例。

属性

Caption

获取编辑器对话框的标题。

Filter

获取对话框的文件筛选字符串(例如“*.txt”)。

IsDropDownResizable

获取一个值,该值指示是否应由用户调整下拉编辑器的大小。

(继承自 UITypeEditor)
Options

获取 URL 生成器要使用的选项。

(继承自 UrlEditor)

方法

EditValue(IServiceProvider, Object)

使用 GetEditStyle() 方法所指示的编辑器样式编辑指定对象的值。

(继承自 UITypeEditor)
EditValue(ITypeDescriptorContext, IServiceProvider, Object)

使用 GetEditStyle(ITypeDescriptorContext) 方法所提供的编辑器样式编辑指定对象的值。

(继承自 UrlEditor)
Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetEditStyle()

获取由 EditValue(IServiceProvider, Object) 方法使用的编辑器样式。

(继承自 UITypeEditor)
GetEditStyle(ITypeDescriptorContext)

获取 EditValue(ITypeDescriptorContext, IServiceProvider, Object) 方法的编辑样式。

(继承自 UrlEditor)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetPaintValueSupported()

指示该编辑器是否支持绘制对象值的表示形式。

(继承自 UITypeEditor)
GetPaintValueSupported(ITypeDescriptorContext)

指示指定的上下文是否支持在指定的上下文内绘制对象值的表示形式。

(继承自 UITypeEditor)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
PaintValue(Object, Graphics, Rectangle)

将指定对象值表示形式绘制到指定的画布上。

(继承自 UITypeEditor)
PaintValue(PaintValueEventArgs)

使用指定的 PaintValueEventArgs 绘制某个对象的值的表示形式。

(继承自 UITypeEditor)
ToString()

返回表示当前对象的字符串。

(继承自 Object)

适用于

另请参阅