110,542
社区成员
发帖
与我相关
我的任务
分享
//继承原Button
public partial class ButtonTip : Button
{
private string tipText;
private ToolTip tip;
public ButtonTip()
{
InitializeComponent();
this.MouseEnter += new EventHandler(ButtonTip_MouseEnter);
this.MouseLeave += new EventHandler(ButtonTip_MouseLeave);
}
void ButtonTip_MouseLeave(object sender, EventArgs e)
{
tip.Dispose();
}
void ButtonTip_MouseEnter(object sender, EventArgs e)
{
tip = new ToolTip();
tip.SetToolTip(this, tipText);
tip.Show(tipText, this, this.Width / 2, -this.Height + 3);
}
[Browsable(true)]
[Description("get or set text would be shown on the button when the point of your mouse is hovering on it!\n获取或设置鼠标指针悬停在按钮上时要显示的文本")]
[Category("TipButton")]
[RefreshProperties(RefreshProperties.All)]
public String TipText
{
get
{
return tipText;
}
set
{
if (value != null)
{
if (value.Length < 1)
{
tipText = Text;
}
else
{
tipText = value;
}
}
else
{
tipText = Text;
}
}
}
}
你可以先定义个BOOL,点第下,换掉背景图片,改为true,在点一下,再把图片换回去,改为false。
做好了,剩下的就是拖控件了。public Form1()
{
InitializeComponent();
for (int i = 0; i < 4; i++)
{
RadioButton rb = new RadioButton()
{
Appearance = Appearance.Button,
Text = "Button " + i,
Location = new Point(30, 30 * i),
};
this.Controls.Add(rb);
}
}