110,570
社区成员
发帖
与我相关
我的任务
分享
public class IconButton : Control
{
public IconButton()
{
this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true);
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
this.BackColor= Color.Transparent;
}
}
/// <summary>
/// 设置透明按钮样式
/// </summary>
private void SetBtnStyle(Button btn)
{
btn.FlatStyle = FlatStyle.Flat;//样式
btn.ForeColor = Color.Transparent;//前景
btn.BackColor = Color.Transparent;//去背景
btn.FlatAppearance.BorderSize = 0;//去边线
btn.FlatAppearance.MouseOverBackColor = Color.Transparent;//鼠标经过
btn.FlatAppearance.MouseDownBackColor = Color.Transparent;//鼠标按下
}
private void btn_MouseHover(object sender, EventArgs e)
{
Button btn = sender as Button;
btn.FlatAppearance.BorderSize = 1;
}
private void btn_MouseLeave(object sender, EventArgs e)
{
Button btn = sender as Button;
btn.FlatAppearance.BorderSize = 0;
}