颜色c = Colors.Red;
如何将上面的color变量从一个私有无效对象传递给另一个私有无效对象?
提前致谢
斯蒂芬妮
private void btnRedClick(object sender, RoutedEventArgs e)
{
Color c = Colors.Red;
}
private void inkCanvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (inkCanvas.EditingMode == InkCanvasEditingMode.None)
{
if(dtm == DrawingToolMode.ellipse)
{
Ellipse myEllipse = new Ellipse();
//Color c = Colors.Red;
System.Windows.Media.SolidColorBrush scb =
new SolidColorBrush(c);
myEllipse.Stroke = (scb);
myEllipse.Fill = (scb);
Point p = Mouse.GetPosition(this.inkCanvas);
InkCanvas.SetTop(myEllipse, p.Y);
InkCanvas.SetLeft(myEllipse, p.X);
myEllipse.Height = 20;
myEllipse.Width = 20;
inkCanvas.Children.Add(myEllipse);
}
}
}
最佳答案
将其存储在私有字段中:
private Color _color;
private void btnRedClick(object sender, RoutedEventArgs e)
{
_color = Colors.Red;
}
private void inkCanvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
Color myLocalColor = _color;
}
我建议您尽管阅读编程101。这是一个非常基本的问题。
关于c# - 在私有(private)空隙之间传递颜色变量,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36174803/