我想從我的鼠標位置向我的網格添加一個橢圓。我如何定義繪製橢圓的位置?將橢圓添加到鼠標位置?
這裏是我的鼠標按下事件:
private void GridCanvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
_sensorPoint = Mouse.GetPosition(GridCanvas);
AddSensor();
}
而且我AddSensor()方法:
private void AddSensor()
{
Ellipse sensorEllipse = new Ellipse();
SolidColorBrush solidColorBrush = new SolidColorBrush();
solidColorBrush.Color = Color.FromArgb(0, 0, 0, 0);
sensorEllipse.Fill = solidColorBrush;
sensorEllipse.StrokeThickness = 2;
sensorEllipse.Stroke = Brushes.Black;
sensorEllipse.Width = 10;
sensorEllipse.Height = 10;
GridCanvas.Children.Add(sensorEllipse);
}
如何添加sensorEllipse其中點擊畫布上的鼠標?
看看[這個問題](http://stackoverflow.com/questions/6818851/change-stackpanel-location-on-a-canvas-programatically)。 – 2012-08-16 06:47:17
鼠標點的類型是Point,我需要將它們拆分爲兩個雙打,以便與Canvas.SetLeft()一起使用。我需要這樣做嗎? – DommyCastles 2012-08-16 06:50:00