0

I need a event that receives the position/location of an control, for example a Image-control, which i move with an animation.

So I found some code from this post that I need, but I can't figure out where to put the code.

Should I put it in some event e.g. the windows loaded event or what? What am I missing?

C#:

var topDescriptor = DependencyPropertyDescriptor.FromProperty(Canvas.TopProperty, typeof(Rectangle)); 
var leftDescriptor = DependencyPropertyDescriptor.FromProperty(Canvas.LeftProperty, typeof(Rectangle)); 

topDescriptor.AddValueChanged(rectangle, rectangle_PositionChanged); 
leftDescriptor.AddValueChanged(rectangle, rectangle_PositionChanged);


//I know where this part goes
    private void rectangle_PositionChanged(object sender, EventArgs e) 
    {     
    ... 
    }

VB.NET:

    Dim topDescriptor = DependencyPropertyDescriptor.FromProperty(Canvas.TopProperty, GetType(Rectangle))
    Dim leftDescriptor = DependencyPropertyDescriptor.FromProperty(Canvas.LeftProperty, GetType(Rectangle))

    topDescriptor.AddValueChanged(rectangle, rectangle_PositionChanged)
    leftDescriptor.AddValueChanged(rectangle, rectangle_PositionChanged)

//I know where this part goes
    Private Sub rectangle_PositionChanged(sender As Object, e As EventArgs)
        ...
    End Sub

Thanks, VenoMDee.

Community
  • 1
  • 1
Jonas Libbe
  • 1,792
  • 1
  • 12
  • 9

1 Answers1

0

Yes, I think that this code should go in the window load event so that the event handlers are hooked up prior to the form being displayed.

competent_tech
  • 44,465
  • 11
  • 90
  • 113
  • There's only one problem... When i try to run the application, it says that "Argument not specified for parameter 'e' of Private Sub rectangle_PositionChanged(sender As Object, e As EventArgs)". What have I done wrong? – Jonas Libbe Dec 08 '11 at 16:28
  • The problem is that Canvas.Top and Canvas.Left are of type System.Double, not Rectangle, so I am not sure how the original code worked. – competent_tech Dec 08 '11 at 17:48