THREAD: Label Movements :)
  1. 05-21-2015, 08:49 PM
    Antonio96C's Avatar
    Antonio96C
    Do a barrel roll!
    Antonio96C's Avatar
    Antonio96C
    Do a barrel roll!
    118
    Posts
    1,597
    Reputation
    Nov 2014
    NextGenUpdate
    Hi NGU
    Label Movements

    In Timer . Interval = 50;
    bool movement;

    You must login or register to view this content.
    if (labelXX.Left < this.ClientSize.Width - labelXX.Width + 10 && movement)
    {
    labelXX.Left++;
    if (labelXX.Left == this.ClientSize.Width - labelXX.Width - 10)
    {
    movement= false;
    }
    }
    if (labelXX.Left > -10 && !movement)
    {
    labelXX.Left--;
    if (labelXX.Left == -10)
    {
    movement= true;
    }
    }


    Thanks Antonio96 :p
    Last edited by Antonio96C ; 05-21-2015 at 08:53 PM.

  2. The Following User Thanked Antonio96C For This Useful Post:


  3. 05-22-2015, 02:27 AM
    jagex's Avatar
    jagex
    Gym leader
    jagex's Avatar
    jagex
    Gym leader
    299
    Posts
    1,649
    Reputation
    Oct 2010
    NextGenUpdate
    Nice job!

    Here is another way with only 2 lines of code using ThicknessAnimation.

    private void moveLabel(Label label, double duration, double fromLeft, double fromTop, double fromRight, double fromBottom, double toLeft, double toTop, double toRight, double toBottom)
    {
    var moveLeft = new ThicknessAnimation(new Thickness(fromLeft, fromTop, fromRight, fromBottom), new Thickness(toLeft, toTop, toRight, toBottom), TimeSpan.FromSeconds(duration));
    label.BeginAnimation(BorderThicknessProperty, moveLeft);
    }