【发布时间】:2013-12-25 22:23:13
【问题描述】:
在form1的顶部我做了:
using System.Windows.Media;
但是在我的代码中我使用笔刷颜色的任何地方我都必须在它之前添加 System.Drawing 例如:
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 时,这就是我需要添加 Media 类的原因:
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.Brushes
错误 5 参数 3:无法从“System.Drawing.Brushes”转换为“System.Drawing.Brush”
开启:第 3 点
错误 6 参数 4:无法从 'System.Drawing.Point' 转换为 'System.Drawing.RectangleF'
在这一行:(System.Drawing.Brushes)brush
错误 3 无法将类型“System.Windows.Media.SolidColorBrush”转换为“System.Drawing.Brushes”
在这一行:System.Drawing.Color color = ((System.Windows.Media.Brushes)brush).Color;
错误 2 无法将类型“System.Windows.Media.SolidColorBrush”转换为“System.Windows.Media.Brushes”
关于这部分:graphics.DrawString
错误 4 'System.Drawing.Graphics.DrawString(string, System.Drawing.Font, System.Drawing.Brush, System.Drawing.RectangleF)' 的最佳重载方法匹配有一些无效参数
并且属性颜色不存在:System.Windows.Media.Color Brushes_color
错误 1 类型名称“Color”在类型“System.Drawing.Brush”中不存在
我想做的就是让用户能够在这一行选择画笔颜色:
graphics.DrawString(text,
this.Font, (System.Drawing.Brushes)brush, point3);
原来的行是:
graphics.DrawString(text,
this.Font, Brushes.Green , point3);
但我希望用户选择画笔的颜色。
【问题讨论】: