Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Everyone,

I have generated the Thumb in wpf on button click as follows and moves around the canvas.

C#
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);



C#
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.
Posted
Comments
Sergey Alexandrovich Kryukov 9-Apr-12 13:04pm    
What are your using this Canvas for? It is designed to allow any kind of overlapping. If you are using canvas for control, this might be not what you need -- use some appropriate Panel class...
--SA
ajit_machhe 9-Apr-12 13:08pm    
thanks for looking into it SA :)

could you please help me with this ??

The reason i used canvas is that i can find the proper position of the control.
(in simple way all i have to get left of canvas from control)The position of the control is important to me.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900