I have a canvas, which, upon a click on the left button of the mouse, has a label created on it in the clicking point. This is the xaml code:
public partial class MainWindow : Window
{
int num = 1;
List <Label> countries = new List<Label>();
public MainWindow()
{
InitializeComponent();
}
private void Canvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
var point = Mouse.GetPosition(Canvas);
Label label = new Label() { Width = 100, Height = 100 };
Canvas.Children.Add(label);
Canvas.SetLeft(label, point.X);
Canvas.SetTop(label, point.Y);
label.Focus();
num++;
countries.Add(label);
}
}
I would like to make it so two different labels would not be able to intersect with each other. The idea is that if the user tries to create a label in a location which would cause it to intersect with another existing label, a message box would pop and tell him to choose another location.
Unfortunately I did not succeed in implementing this. If anyone could help, I would be very glad. Help will be much appreciated :)