我將轉換顏色問題轉換爲十六進制。紅色下劃線低於System.Drawing.ColorTranslator.FromHtml("paint")
和rect.Color;
變量paint
是靜態的 - 現在。將顏色轉換爲十六進制c#
在我看來,問題是變量的類型公共System.Drawing.SolidBrush Color
在Rect
類
List<Rect> rects = new List<Rect>();
rects.Add(new Rect()
{
Width = x,
Height = y,
Left = w,
Top = h,
Fill = (System.Windows.Media.Brush)(new BrushConverter()).ConvertFromString(paint)
});
foreach (Rect rect in rects)
{
Rectangle r = new Rectangle
{
Width = rect.Width,
Height = rect.Width,
Fill = rect.Fill
};
Canvas.SetLeft(r, rect.Left);
Canvas.SetTop(r, rect.Top);
canvas.Children.Add(r);
}
}
class Rect
{
public int Width { get; set; }
public int Height { get; set; }
public int Left { get; set; }
public int Top { get; set; }
public System.Windows.Media.Brush Fill { get; set; }
}
private void rectangle_Click(object sender, RoutedEventArgs e)
{
choose r1 = new choose();
var paint = "#FFA669D1";
int x = int.Parse(beginx.Text);
int y = int.Parse(beginy.Text);
int w = int.Parse(wid.Text);
int h = int.Parse(hei.Text);
if (!((x > canvas.ActualWidth) || (y > canvas.ActualHeight) || (w > canvas.ActualWidth) || (h > canvas.ActualHeight)))
{
r1.rectangle(x, y, w, h, paint, canvas);
}
}
首先擺脫引用「paint」:''System.Drawing.ColorTranslator.FromHtml(paint)'' – LocEngineer
「塗料」中有什麼樣的變量? – mm8
油漆是字符串 – macieqqq