ajit machhe

ajit machhe

  • NA
  • 1
  • 0

how to stop overlapping controls runtime.

May 18 2012 4:00 PM
Hi Everyone,
 
I have generated the Thumb in wpf on button click as follows and moves around the canvas.

Thumb addthumb = new Thumb();
                    addthumb.Height = 20;
                    addthumb.Width = lenght_[i]+25;
                    addthumb.Name = "L" + i.ToString() + "P" + i.ToString();
                    addthumb.Background = System.Windows.Media.Brushes.Orange;
                    addthumb.DragDelta += new DragDeltaEventHandler(myThumb_DragDelta);
                    Canvas.SetLeft(addthumb, position_array[balls]+25);
                    Canvas.SetTop(addthumb, 20);
                    canvas_container.Children.Add(addthumb);
 

private void myThumb_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
       {
           FrameworkElement element = sender as FrameworkElement;
           Canvas.SetLeft(element, Canvas.GetLeft(element) + e.HorizontalChange);
           lbl_Heightshow.Content = element.Height;
           lbl_widthshow.Content = element.Width;
           lbl_Slub_name.Content = element.Name;
           lbl_leftposition.Content = Canvas.GetLeft(element).ToString();
           if (Canvas.GetLeft(element) == 0)
           {
               lbl_leftposition.Content = "0";
           }
           else if (Canvas.GetLeft(element) < 0)
           {
               lbl_leftposition.Content = "0";
               Canvas.SetLeft(element, 0);
           }
           else if (Canvas.GetLeft(element) + element.Width > canvas_container.ActualWidth)
           {
               lbl_leftposition.Content = (canvas_container.ActualWidth - element.Width).ToString();
               Canvas.SetLeft(element, canvas_container.ActualWidth - element.Width);
           }
}

now what i want is...
 
the generated 'thums' should not overlap each on other while we drag them on the canvas.
 
please help and Thanks.