Mega Code Archive

 
Categories / VB.Net Tutorial / WPF
 

Get position on a Canvas with Canvas GetLeft

<Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     x:Class="Thumb_wcp.Pane1">   <Canvas Width="100" Height="100" Name="myCanvasStretch">     <TextBox Name="changes"           Width="{Binding ElementName=myCanvasStretch,Path=Width}"            Height="{Binding ElementName=myCanvasStretch,Path=Height}"           Text="Size: 100, 100"/>     <Thumb Name="myThumb" Canvas.Left="80" Canvas.Top="80" Background="Blue"            Width="20" Height="20" DragDelta="onDragDelta"/>   </Canvas> </Canvas> //File:Window.xaml.vb Imports System Imports System.Windows Imports System.Windows.Controls Imports System.Windows.Controls.Primitives Imports System.Windows.Documents Imports System.Windows.Navigation Imports System.Windows.Shapes Imports System.Windows.Data Imports System.Windows.Media Namespace Thumb_wcp   Public Partial Class Pane1     Inherits Canvas     Private Sub onDragDelta(sender As Object, e As DragDeltaEventArgs)       Dim yadjust As Double = myCanvasStretch.Height + e.VerticalChange       Dim xadjust As Double = myCanvasStretch.Width + e.HorizontalChange       If (xadjust >= 0) AndAlso (yadjust >= 0) Then         myCanvasStretch.Width = xadjust         myCanvasStretch.Height = yadjust         Canvas.SetLeft(myThumb, Canvas.GetLeft(myThumb) + e.HorizontalChange)         Canvas.SetTop(myThumb, Canvas.GetTop(myThumb) + e.VerticalChange)         Console.WriteLine(myCanvasStretch.Width)         Console.WriteLine(myCanvasStretch.Height)       End If     End Sub   End Class End Namespace