我很想编写一段有关如何使用C#的代码。因此,对于真正的程序员来说,这可能是一个非常简单的问题。
我乱丢垃圾了。但是我过去一直在搜索,我只是对这里的问题感到好奇。如果有人能为我指出这一点,我会很高兴。正手谢谢!
private void ButtonDraw_Click(object sender, RoutedEventArgs e)
{
SolidColorBrush color = new SolidColorBrush(Colors.White);
MakeRectangle(drawingArea, color, 10, 20, 20);
MakeRectangle(drawingArea, color, 10, 20, 40);
MakeRectangle(drawingArea, color, 10, 20, 60);
}
private void MakeRectangle(Canvas drawing, SolidColorBrush brushcolor, double xPos, double yPos, double size)
{
Rectangle vierkant = new Rectangle();
vierkant.Height = size;
vierkant.Width = size;
vierkant.Margin = new Thickness(xPos, yPos, 0, 0);
vierkant.Stroke = brushcolor;
drawing.Children.Add(MakeRectangle);
}
答案 0 :(得分:1)
您需要将vierkant Rectangle对象传递到drawing.Children.Add()方法中,如下所示:
private void MakeRectangle(Canvas drawing, SolidColorBrush brushcolor, double xPos, double yPos, double size)
{
Rectangle vierkant = new Rectangle();
vierkant.Height = size;
vierkant.Width = size;
vierkant.Margin = new Thickness(xPos, yPos, 0, 0);
vierkant.Stroke = brushcolor;
drawing.Children.Add(vierkant );
}