如何识别矩形是否包含in中的Text块

时间:2013-06-29 18:38:23

标签: c# wpf contains textblock

我正在创建这个程序,用户将文本块拖放/拖放到矩形中,然后在他/她将文本块放入矩形时存储该特定文本块的内容。

我想出了如何进行拖放操作,但我无法弄清楚如何检查矩形是否包含文本块。

到目前为止,这是代码:

bool captured = false;
double x_shape, x_canvas, y_shape, y_canvas;
UIElement source = null;



private void shape_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
  source = (UIElement)sender;
  Mouse.Capture(source);
  captured = true;
  x_shape = Canvas.GetLeft(source);
  x_canvas = e.GetPosition(LayoutRoot).X;
  y_shape = Canvas.GetTop(source);
  y_canvas = e.GetPosition(LayoutRoot).Y;
}

private void shape_MouseMove(object sender, MouseEventArgs e)
{
  if (captured)
  {
    double x = e.GetPosition(LayoutRoot).X;
    double y = e.GetPosition(LayoutRoot).Y;
    x_shape += x - x_canvas;
    Canvas.SetLeft(source, x_shape);
    x_canvas = x;
    y_shape += y - y_canvas;
    Canvas.SetTop(source, y_shape);
    y_canvas = y;
  }
}

private void shape_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
  Mouse.Capture(null);
  captured = false;
}



private void rectangle1_MouseEnter(object sender, MouseEventArgs e)
{
    if (Mouse.Capture(null))
    {
        textBox1.Text = "test";


    }
}

顺便提一下,“形状”事件适用于文本块。 我试图找到一个快捷方式,并使用rectangle1_MouseEnter事件,如果未单击鼠标,则存储值(不包括存储值的代码)。但问题是,这个想法不起作用,因为textBox1.Text =“test”没有注册,我不明白为什么不是。

0 个答案:

没有答案
相关问题