Click here to Skip to main content
16,017,297 members

Comments by Member 10838492 (Top 11 by date)

Member 10838492 7-Jul-14 1:23am View    
really great links
Member 10838492 2-Jul-14 3:24am View    
hey Hi
its not the solution yaar, its just a part of my code, I have by mistake posted here
Member 10838492 1-Jul-14 1:03am View    
hiThe problem is i have a images on the canvas and i want to select the images on click and drag... for the same purpose i have used two canvas...
1. the canvas on which images are there (.png format)
2. the canvas which is used for click and drag.

here i s the code for the same

////////////////////////////////////////////////////////////////Code///////////////////////////
XAML;



MouseDown="Grid_MouseDown"
MouseUp="Grid_MouseUp"
MouseMove="Grid_MouseMove"
Background="Transparent"
> <!---->
<canvas name="myCanvas" horizontalalignment="Center" verticalalignment="Stretch" allowdrop="True" drop="DropImage" mouserightbuttondown="myCanvas_MouseRightButtonDown_1" width="648" margin="9,9,9,7" grid.column="1" grid.row="3">
<!---->
<image margin="2,0,0,10" name="imgPhoto" mouseleftbuttondown="DragImage" allowdrop="True" mouserightbuttondown="Image_MouseRightButtonDown_1">
Stretch="Fill" Grid.Row="1" Grid.ColumnSpan="4" Grid.Column="1" Grid.RowSpan="2" />

<canvas.contextmenu>







</canvas.contextmenu>
<!---->


<!---->
<canvas>
<!-- This canvas is overlaid over the previous canvas and is used to
place the rectangle that implements the drag selection box. -->

x:Name="selectionBox"
Visibility="Collapsed"
Stroke="Black"
StrokeThickness="1"
/>
</canvas>
<!---->


XAML.cs

bool mouseDown = false; // Set to 'true' when mouse is held down.
Point mouseDownPos; // The point where the mouse button was clicked down.

private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
{
// Capture and track the mouse.
mouseDown = true;
mouseDownPos = e.GetPosition(theGrid);
theGrid.CaptureMouse();

// Initial placement of the drag selection box.
Canvas.SetLeft(selectionBox, mouseDownPos.X);
Canvas.SetTop(selectionBox, mouseDownPos.Y);
selectionBox.Width = 0;
selectionBox.Height = 0;

// Make the drag selection box visible.
selectionBox.Visibility = Visibility.Visible;
myCanvas.Children.Contains(selectedElement);
}

private void Grid_MouseUp(object sender, MouseButtonEventArgs e)
{
// Release the mouse capture and stop tracking it.
mouseDown = false;
theGrid.ReleaseMouseCapture();

// Hide the drag selection box.
selectionBox.Visibility = Visibility.Collapsed;

Point mouseUpPos = e.GetPosition(theGrid);


}

private void Grid_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
{
if (mouseDown)
{

// When the mouse is held down, reposition the drag selection box.

Point mousePos = e.GetPosition(theGrid);

if (mouseDownPos.X < mousePos.X)
{
Canvas.SetLeft(selectionBox, mouseDownPos.X);
selectionBox.Width = mousePos.X - mouseDownPos.X;
}
else
{
Canvas.SetLeft(selectionBox, mousePos.X);
selectionBox.Width = mouseDownPos.X - mousePos.X;
}

if (mouseDownPos.Y < mousePos.Y)
{
Canvas.SetTop(selectionBox, mouseDownPos.Y);
selectionBox.Height = mousePos.Y - mouseDownPos.Y;
}
else
{
Canvas.SetTop(selectionBox, mousePos.Y);
selectionBox.Height = mouseDownPos.Y - mousePos.Y;
}

myCanvas.Children.Contains(selectedElement);

if (selected)
{
selected = false;
if (selectedElement != null)
{
// Remove the adorner from the selected element

//<<i have justifed it after adding the delete button becasue of adorner layer issue>>

aLayer.Remove(aLayer.GetAdorners(selectedElement)[0]);
selectedElement = null;
}
}


if (e.Source != myCanvas)
{
_isDown = true;
_startPoint = e.GetPosition(myCanvas);

selectedElement = e.Source as UIElement;

_originalLeft = Canvas.GetLeft(selectedElement);
_originalTop = Canvas.GetTop(selectedElement);

aLayer = AdornerLayer.GetAdornerLayer(selectedElement);

aLayer.Add(new ResizingAdorner(selectedElement));
selected = true;
e.Handled = true;

}
}
}
Member 10838492 1-Jul-14 0:56am View    
Deleted
select the images
Member 10838492 1-Jul-14 0:56am View    
I have updated the code and the issue, please do have a look at it :)