winform中按钮透明的方法

把Button设为透明的方法:
1.修改 FlatAppearance属性下的BorderSize 为0
  修改 FlatStyle 的属性为 Flat

2.

/// <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;
}

 

lable可以直接使用label1.BackColor = Color.Transparent;使其透明

 

posted @ 2018-07-10 16:18  傻蛋儿  阅读(2114)  评论(0编辑  收藏  举报