MailFileEditor 类

定义

提供可用于在设计时选择和编辑属性的邮件文件名的用户界面。Provides a user interface for selecting and editing a mail file name for a property at design time.

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类的实例与自定义控件内包含的属性相关联。The following code example demonstrates how to associate an instance of the MailFileEditor class with a property that is contained within a custom control. 在设计图面中编辑控件属性时, MailFileEditor类提供用户界面, 以便为属性值选择和编辑邮件文件名。When the control property is edited in the design surface, the MailFileEditor class provides the user interface to select and edit a mail file name for the property value.

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

注解

类是一个UITypeEditor对象, 该对象可在设计时用于选择和编辑作为字符串的邮件文件名, 并将该字符串分配给控件属性。 MailFileEditorThe MailFileEditor class is an UITypeEditor object that can be used at design time to select and edit a mail file name as a string, and assign the string to a control property. 例如, EmbeddedMailObject控件在设计时MailFileEditor使用类来Path设置属性的值。For example, the EmbeddedMailObject control uses the MailFileEditor class at design time to set the value of the Path property.

EditorAttribute使用特性MailFileEditor将与属性相关联。Use the EditorAttribute attribute to associate the MailFileEditor with a property. 在设计图面中编辑关联的属性时, 设计器宿主将调用EditValue方法。When the associated property is edited in the design surface, the designer host calls the EditValue method. EditValue方法会显示一个对话框, 用于从筛选的文件列表中选择邮件文件名, 并返回用户选择的文件名。The EditValue method displays a dialog box for selecting a mail file name from a filtered list of files, and returns the file name that is selected by the user. GetEditStyle方法指示用户界面的显示样式。The GetEditStyle method indicates the display style of the user interface.

从派生类MailFileEditor , 以定义邮件文件名称属性的自定义编辑器。Derive a class from the MailFileEditor to define a custom editor for a mail file name property. 例如, 派生类可以重写EditValue方法, 并使用自定义邮件文件筛选器或标题来OpenFileDialog显示实例。For example, a derived class can override the EditValue method, and display an OpenFileDialog instance with a custom mail file filter or title.

构造函数

MailFileEditor()

初始化 MailFileEditor 类的新实例。Initializes a new instance of the MailFileEditor class.

属性

Caption

获取编辑器对话框的标题。Gets the caption for the editor dialog.

Filter

获取对话框的文件筛选字符串(例如“*.txt”)。Gets the file filter string for the dialog (such as "*.txt").

IsDropDownResizable

获取一个值,该值指示是否应由用户调整下拉编辑器的大小。Gets a value indicating whether drop-down editors should be resizable by the user.

(继承自 UITypeEditor)
Options

获取 URL 生成器要使用的选项。Gets the options for the URL builder to use.

(继承自 UrlEditor)

方法

EditValue(IServiceProvider, Object)

使用 GetEditStyle() 方法所指示的编辑器样式编辑指定对象的值。Edits the value of the specified object using the editor style indicated by the GetEditStyle() method.

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

使用 GetEditStyle(ITypeDescriptorContext) 方法所提供的编辑器样式编辑指定对象的值。Edits the value of the specified object using the editor style provided by the GetEditStyle(ITypeDescriptorContext) method.

(继承自 UrlEditor)
Equals(Object)

确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetEditStyle()

获取由 EditValue(IServiceProvider, Object) 方法使用的编辑器样式。Gets the editor style used by the EditValue(IServiceProvider, Object) method.

(继承自 UITypeEditor)
GetEditStyle(ITypeDescriptorContext)

获取 EditValue(ITypeDescriptorContext, IServiceProvider, Object) 方法的编辑样式。Gets the editing style of the EditValue(ITypeDescriptorContext, IServiceProvider, Object) method.

(继承自 UrlEditor)
GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetPaintValueSupported()

指示该编辑器是否支持绘制对象值的表示形式。Indicates whether this editor supports painting a representation of an object's value.

(继承自 UITypeEditor)
GetPaintValueSupported(ITypeDescriptorContext)

指示指定的上下文是否支持在指定的上下文内绘制对象值的表示形式。Indicates whether the specified context supports painting a representation of an object's value within the specified context.

(继承自 UITypeEditor)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

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

将指定对象值表示形式绘制到指定的画布上。Paints a representation of the value of the specified object to the specified canvas.

(继承自 UITypeEditor)
PaintValue(PaintValueEventArgs)

使用指定的 PaintValueEventArgs 绘制某个对象的值的表示形式。Paints a representation of the value of an object using the specified PaintValueEventArgs.

(继承自 UITypeEditor)
ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)

适用于

另请参阅