C# 我正在尝试使用SolidColorBrush,但是出现了许多无法转换类型的错误。如何修复它并使用SolidColorBrush?
在表格1的顶部,我做了:C# 我正在尝试使用SolidColorBrush,但是出现了许多无法转换类型的错误。如何修复它并使用SolidColorBrush?,c#,winforms,C#,Winforms,在表格1的顶部,我做了: using System.Windows.Media; 但是,在我的代码中,我使用钢笔画笔的地方,我必须在系统之前添加颜色。例如,绘图: System.Drawing.Pen(System.Drawing.Color.Green, 2f)) System.Drawing.Pen(Color.Green, 2f)) 如果我不这样做,我将得到一个错误,例如: System.Drawing.Pen(System.Drawing.Color.Green, 2f)) Sy
using System.Windows.Media;
但是,在我的代码中,我使用钢笔画笔的地方,我必须在系统之前添加颜色。例如,绘图:
System.Drawing.Pen(System.Drawing.Color.Green, 2f))
System.Drawing.Pen(Color.Green, 2f))
如果我不这样做,我将得到一个错误,例如:
System.Drawing.Pen(System.Drawing.Color.Green, 2f))
System.Drawing.Pen(Color.Green, 2f))
错误2“Color”是“System.Drawing.Color”和“System.Windows.Media.Color”之间的不明确引用
所以我在前面添加了System.Drawing,这行没有错误
问题是当我尝试在我的方法中使用SolidColorBrush时,这就是为什么我需要添加媒体类:
private void DrawText(string text, System.Drawing.Color pen_color, System.Windows.Media.Color brushes_color, Graphics graphics, int point1, int point2, Point point3)
{
SolidColorBrush brush = new SolidColorBrush(brushes_color);
System.Drawing.Color color = ((System.Windows.Media.Brushes)brush).Color;
using (System.Drawing.Pen pen = new System.Drawing.Pen(pen_color, 6f))
{
Point pt1 = new Point(point1); // 369, 90
Point pt2 = new Point(point2); // 469, 90
graphics.DrawLine(pen, pt1, pt2);
}
graphics.DrawString(text,
this.Font, (System.Drawing.Brushes)brush, point3); // 480, 83
}
我收到一些错误:
在这一行上:System.Drawing.Brush
错误5参数3:无法从“System.Drawing.Brush”转换为“System.Drawing.Brush”
关于:第3点
错误6参数4:无法从“System.Drawing.Point”转换为“System.Drawing.RectangleF”
在这一行上:(系统.绘图.画笔)画笔
错误3无法将类型“System.Windows.Media.SolidColorBrush”转换为“System.Drawing.Brush”
在这一行:System.Drawing.Color=((System.Windows.Media.brush)brush)Color
错误2无法将类型“System.Windows.Media.SolidColorBrush”转换为“System.Windows.Media.Brush”
此部分:graphics.DrawString
错误4“System.Drawing.Graphics.DrawString(string,System.Drawing.Font,System.Drawing.Brush,System.Drawing.RectangleF)”的最佳重载方法匹配具有一些无效参数
属性颜色不存在:System.Windows.Media.Color\u Color
错误1类型“System.Drawing.Brush”中不存在类型名称“Color”
我想做的就是让用户能够在这一行上选择画笔的颜色:
graphics.DrawString(text,
this.Font, (System.Drawing.Brushes)brush, point3);
在最初的版本中,该行是:
graphics.DrawString(text,
this.Font, Brushes.Green , point3);
但是我想让用户选择画笔的颜色
问题是当我试图在我的方法中使用SolidColorBrush时,这就是为什么我需要添加媒体类
你不需要那个。调用System.Drawing
中的类。删除System.Windows.Media
参考