多边形鼠标左按钮向下不能射击和多边形儿童可能与否?

时间:2011-12-15 09:58:29

标签: wpf wpf-controls

我有一个有MouseLeftButtonDown事件的多边形。当我在其边缘附近点击(比如从边框内部说出10个像素)时,不会调用该事件。这可能是什么问题?

其次,我们可以添加多边形的子项吗?

private void Window_Loaded(object sender, RoutedEventArgs e) 
{
    Polygon p = new Polygon() { 
    Stroke = Brushes.Black, 
    StrokeThickness = 2, 
    Points = new PointCollection() {new Point(10,10), new Point(50,10), 
    new Point(56, 45) }};    
    p.MouseLeftButtonDown += new MouseButtonEventHandler(p_MouseLeftButtonDown);
    mygrd.Children.Add(p); 
}

void p_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) 
{ 
    MessageBox.Show("Entered"); 
}

1 个答案:

答案 0 :(得分:1)

为多边形提供填充画笔,并触发鼠标事件

private void Window_Loaded(object sender, RoutedEventArgs e)
{
  Polygon p = new Polygon() {
    Stroke = Brushes.Black,
    StrokeThickness = 2,
    Fill = Brushes.Transparent, // or something else
    Points = new PointCollection() {new Point(10,10), new Point(50,10), new Point(56, 45) }};
  p.MouseLeftButtonDown += new MouseButtonEventHandler(p_MouseLeftButtonDown);
  mygrd.Children.Add(p);
}