本文介绍了我想将一个矩形从一个Event函数传递给另一个Event函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将矩形从一个函数传递给第二个函数
由于某种原因,rectangel读取事件函数为null
我该怎么做?
I want to to pass a rectangle from one function to a second function
For some reason the rectangel read to the event function as null
How can I do this?
private Point startpoint;
private Rectangle rect;
private void canvas1_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
startpoint = Mouse.GetPosition(canvas1);
// the rectengle that i creat and i what to pass him to the canvas1_MouseMove Event function
Rectangle rect = new Rectangle();
rect.Stroke = Brushes.Black;
rect.StrokeThickness = 1;
canvas1.Children.Add(rect);
}
private void canvas1_MouseMove(object sender, MouseEventArgs e)
{
//to here i want to pass the rectangle
// when i debug the code the rect value is null!
// so i cant control his Properties
rect.Width = 5;// her i got excsption
//"Object reference not set to an instance of an object."
rect.Height = 6;
}
推荐答案
这篇关于我想将一个矩形从一个Event函数传递给另一个Event函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!