///如未特别说明,本人所发表的技术文章都为原创, 任何人引用都请注明出处,并包含本声明
///作者: CSDN网名alias88,邮件: [email protected] _,QQ:63343
_
__
using
System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.ComponentModel.Design;
using System.Drawing.Design;
using System.Diagnostics;
namespace upSystem.upControls
{
///
1<summary>
2
3/// 实现了Format和NullText属性并且带按钮的文本框
4
5/// </summary>
public class upButtonTextBox : System.Windows.Forms.TextBox
{
///
1<summary>
2
3/// 必需的设计器变量。
4
5/// </summary>
private System.ComponentModel.Container components = null ;
private Binding bd= null ;
private TypeConverter typeConverter= null ;
private IFormatProvider formatInfo= null ;
private System.Reflection.MethodInfo parseMethod;
private string nullText="",format="";
private string _Format= string .Empty;
private Type dataType;
private System.Windows.Forms.Button _Button;
public event System.EventHandler CmdClick ;
public upButtonTextBox(): base ()
{
InitializeComponent();
this .DataBindings.CollectionChanged += new CollectionChangeEventHandler(DataBindings_CollectionChanged);
}
///
1<summary>
2
3/// 清理所有正在使用的资源。
4
5/// </summary>
protected override void Dispose( Boolean disposing )
{
if ( disposing )
{
if (components != null )
{
components.Dispose();
}
}
base .Dispose( disposing );
}
#region 组件设计器生成的代码
///
1<summary>
2
3/// 设计器支持所需的方法 - 不要使用代码编辑器
4
5/// 修改此方法的内容。
6
7/// </summary>
private void InitializeComponent()
{
this ._Button = new System.Windows.Forms.Button();
this .SuspendLayout();
//
// _Button
//
this ._Button.BackColor = System.Drawing.Color.ForestGreen;
this ._Button.Cursor = System.Windows.Forms.Cursors.Default;
this ._Button.Dock = System.Windows.Forms.DockStyle.Right;
this ._Button.Location = new System.Drawing.Point(76, 0);
this ._Button.Name = "_Button";
this ._Button.Size = new System.Drawing.Size(20, 17);
this ._Button.TabIndex = 0;
this ._Button.Text = ">";
this ._Button.Visible = false ;
this ._Button.Click += new System.EventHandler( this .btnCommand_Click);
//
// upButtonTextBox
//
this .Controls.Add( this ._Button);
this .ResumeLayout( false );
}
#endregion
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private void DataBindings_CollectionChanged( object sender, CollectionChangeEventArgs e)
{
try
{
dataType= null ;
if (bd!= null )
{
bd.Parse -= new ConvertEventHandler(bd_Parse);
bd.Format -= new ConvertEventHandler(bd_Format);
}
bd= DataBindings["Text"];
if (bd!= null )
{
bd.Parse += new ConvertEventHandler(bd_Parse);
bd.Format += new ConvertEventHandler(bd_Format);
if (bd.BindingManagerBase != null )
DataType=bd.BindingManagerBase.GetItemProperties()[bd.BindingMemberInfo.BindingField ].PropertyType;
}
}
catch { throw ;}
}
[
Category("格式"),
Editor( typeof (upTypeSelectEditor), typeof (UITypeEditor)),
DefaultValue( typeof (System.String)),
Description("文本框的数据类型")
]
public Type DataType
{
get { return dataType;}
set
{
dataType= value ;
if (dataType!= null && dataType != typeof ( object ))
{
this .typeConverter = TypeDescriptor.GetConverter(dataType);
Type[] typeArray1 = new Type[2] { typeof ( string ), typeof (IFormatProvider) } ;
this .parseMethod = dataType.GetMethod("Parse", typeArray1);
}
}
}
[
Category("格式"),
DefaultValue("无"),
Description("值为Null要显示的值")
]
public string NullText
{
get { return nullText;}
set {nullText= value ; }
}
[
Category("格式"),
<