我自己的想法是这样子。
控件上有一个属性设置为是的时候,当我在选定文本框为输入焦点的时候,里面最右边能显示一个可以有单击事件的小按钮。如果文本框失去焦点则按钮消失,同时单击事件不被激发。
如果控件的这个属性设置为否,则与普通文本框没有区别。
我自己做了一个,但是它总是不能显示出来那个按钮。
mark
LG
不不是把??
我怎么觉得好容易啊
关注
UP
谢谢各位捧场。
这样做:
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);
}
}
}
}
支持楼上的
谢谢hbxtlhx(下着春雨的天)
我结帖吧。
楼上的楼上正确
控件上有一个属性设置为是的时候,当我在选定文本框为输入焦点的时候,里面最右边能显示一个可以有单击事件的小按钮。如果文本框失去焦点则按钮消失,同时单击事件不被激发。
如果控件的这个属性设置为否,则与普通文本框没有区别。
我自己做了一个,但是它总是不能显示出来那个按钮。
1楼
mark
2楼
LG
3楼
不不是把??
我怎么觉得好容易啊
4楼
关注
5楼
UP
6楼
谢谢各位捧场。
7楼
这样做:
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);
}
}
}
}
8楼
支持楼上的
9楼
谢谢hbxtlhx(下着春雨的天)
我结帖吧。
10楼
楼上的楼上正确