是否还有更好的窗体透明的方法,可以解决字体毛边的问题。
我现在窗体透明的方法是:但是这样就会有
this.BackColor = Color.White;
this.TransparencyKey = Color.White;
看到有白边怎么办?
处理相近色
string 字体颜色16进制 ="FF0000";
Color 透明色= HexToColor相近(字体颜色16进制);
this.BackColor = 透明色;
this.TransparencyKey = 透明色;
//文字颜色
label1.ForeColor = HexToColor(字体颜色16进制);
//16进制转化
/// <summary>
/// hex转换到color
/// </summary>
/// <param name="hex"></param>
/// <returns></returns>
public Color HexToColor(string hex)
{
byte br = byte.Parse(hex.Substring(0, 2), System.Globalization.NumberStyles.HexNumber);
byte bg = byte.Parse(hex.Substring(2, 2), System.Globalization.NumberStyles.HexNumber);
byte bb = byte.Parse(hex.Substring(4, 2), System.Globalization.NumberStyles.HexNumber);
Color c = Color.FromArgb(50, br, bg, bb);
return c;
}
public Color HexToColor相近(string hex)
{
int br = int.Parse(hex.Substring(0, 2), System.Globalization.NumberStyles.HexNumber);
int bg = int.Parse(hex.Substring(2, 2), System.Globalization.NumberStyles.HexNumber);
int bb = int.Parse(hex.Substring(4, 2), System.Globalization.NumberStyles.HexNumber);
if (br > 20)
{
br = br - 5;
}
if (bg > 20)
{
bg = bg - 5;
}
if (bb > 20)
{
bb = bb - 5;
}
// MessageBox.Show(br.ToString());
Color c = Color.FromArgb( br, bg, bb);
return c;
}
看效果