这样做:using System;
using System.Drawing;
using System.Windows.Forms;namespace ViewControl
{
/// <summary>
/// ButTextBox 的摘要说明。
/// </summary>
public class ButTextBox: System.Windows.Forms.TextBox
{
private Button m_Button;
private bool m_AllowShowButton;
public delegate void ClickButtonDelegate(object sender);
public event ClickButtonDelegate OnClickButton; public ButTextBox()
{
//
// TODO: 在此处添加构造函数逻辑
//
//this.SetStyle(ControlStyles.DoubleBuffer,true);
m_Button = new Button();
m_Button.Size = new Size(this.Height,this.Height-4);
m_Button.Location = new Point(this.Width - this.m_Button.Width-4,0);
m_Button.BackColor = System.Drawing.SystemColors.Control;
m_Button.Click +=new EventHandler(m_Button_Click);
m_Button.Cursor = Cursors.Default;
m_Button.Visible = m_AllowShowButton;
this.Controls.Add(m_Button);
} public bool AllowShowButton
{
get
{
return m_AllowShowButton;
}
set
{
m_AllowShowButton = value;
}
} protected override void OnEnter(EventArgs e)
{
this.m_Button.Visible = m_AllowShowButton;
base.OnEnter (e);
} protected override void OnLeave(EventArgs e)
{
this.m_Button.Visible = false;
base.OnLeave (e);
} private void m_Button_Click(object sender, EventArgs e)
{
if (OnClickButton!=null)
{
OnClickButton(this);
}
}
}
}