我正试图为一个TextBox添加水印。TextBox.Background是System.Windows.Media.Brush。我需要Graphics.FillRectangle(System.Drawing.Brush....)
有没有办法把中间画笔转换成画笔?
发布于 2013-10-24 16:30:20
试试这个
System.Drawing.Brush b = new System.Drawing.SolidBrush((System.Drawing.Color)new System.Drawing.ColorConverter().ConvertFromString(new System.Windows.Media.BrushConverter().ConvertToString(mediabrush)));发布于 2022-04-17 02:52:11
这也适用于UWP和WinUI。用法:
var newBrush = new System.Drawing.SolidBrush(brush.ToSystemDrawingColor())internal static System.Drawing.Color ToSystemDrawingColor(this Brush? brush)
{
if (brush == null)
{
return System.Drawing.Color.Transparent;
}
if (brush is not SolidColorBrush solidColorBrush)
{
throw new NotImplementedException();
}
var color = solidColorBrush.Color;
return System.Drawing.Color.FromArgb(
alpha: color.A,
red: color.R,
green: color.G,
blue: color.B);
}https://stackoverflow.com/questions/19570593
复制相似问题