gpt4 book ai didi

c# - 在私有(private)空隙之间传递颜色变量

转载 作者:太空宇宙 更新时间:2023-11-03 18:25:09 24 4
gpt4 key购买 nike

颜色 c = Colors.Red;

如何将上面的颜色变量从一个私有(private)空隙传递到另一个私有(private)空隙?提前致谢斯蒂芬妮

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 c = Color.Blue; // Set default color

private void btnRedClick(object sender, RoutedEventArgs e)
{
c = Color.Red;
}

private void inkCanvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (inkCanvas.EditingMode == InkCanvasEditingMode.None)
{
if(dtm == DrawingToolMode.ellipse)
{
Ellipse myEllipse = new Ellipse();
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);
}
}

}

关于c# - 在私有(private)空隙之间传递颜色变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36174803/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com