I am creating wpf window application. where i am adding images dynamically and the images are move freely with mouse down event on x-axis over the canvas.
what i need to do is
1> any image should not over lap on other image and they must have atleast 30pixel distance between them.
2> images should be stay in canvas. they should not go out of the canvas.
//--------------------------------------------------------wpf code-------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------
//------------------------------------------------- c# code --------------------------------------------------------------//-------------------------------------------------------------------------------------------------------------------------
public partial class MainWindow : Window
{
Point anchorPoint;
Point currentPoint;
bool isInDrag = false;
public MainWindow()
{
InitializeComponent();
Point anchorPoint;
Point currentPoint;
bool isInDrag = false;
}
private void image1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
FrameworkElement element = sender as FrameworkElement;
anchorPoint = e.GetPosition(null);
element.CaptureMouse();
isInDrag = true;
e.Handled = true;
}
private void image1_MouseMove(object sender, MouseEventArgs e)
{
if (isInDrag)
{
// FrameworkElement element = sender as FrameworkElement;
currentPoint = e.GetPosition(null);
imageTransform.X += (currentPoint.X - anchorPoint.X);
// imageTransform.Y += (currentPoint.Y - anchorPoint.Y);
label1.Content = imageTransform.X.ToString();
if (imageTransform.X > 120)
{
MessageBox.Show("grater");
}
anchorPoint = currentPoint;
}
}
private void image1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
if (isInDrag)
{
FrameworkElement element = sender as FrameworkElement;
element.ReleaseMouseCapture();
isInDrag = false;
e.Handled = true;
}
}
private void image1_MouseWheel(object sender, MouseWheelEventArgs e)
{
//// var st = (ScaleTransform)image.RenderTransform;
// var st = (ScaleTransform)image1.RenderTransform;
// double zoom = e.Delta > 0 ? .2 : -.2;
// st.ScaleX += zoom;
// st.ScaleY += zoom;
}
}
ajit machhePosted Jan 6, 2012, 2:56 PM
1> any image should not over lap on other image and they must have atleast 30pixel distance between them.
remains
ajit machhePosted Jan 6, 2012, 2:55 PM
ajit machhePosted Jan 6, 2012, 10:39 AM