[英]Im trying to use SolidColorBrush but getting many Cannot convert type errors how can i fix it and use the SolidColorBrush?
在form1的tope我做了:
using System.Windows.Media;
但隨后在我的代碼中,我使用Pen Brush Color我必須在它之前添加System.Drawing例如:
System.Drawing.Pen(System.Drawing.Color.Green, 2f))
如果我不這樣做,我會得到一個錯誤,例如:
System.Drawing.Pen(Color.Green, 2f))
錯誤2“顏色”是'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)刷
錯誤3無法將類型'System.Windows.Media.SolidColorBrush'轉換為'System.Drawing.Brushes'
在這一行:System.Drawing.Color color =((System.Windows.Media.Brushes)刷).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)'的最佳重載方法匹配有一些無效的參數
並且屬性Color不存在:System.Windows.Media.Color brushes_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時,這就是我需要添加Media類的原因
你不需要那個。 System.Drawing
的類稱為SolidBrush
。 刪除System.Windows.Media
參考。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.