Page 1 of 1

moving controls at runtime

Posted: Sun Nov 20, 2011 9:49 pm
by Bogoh67
ok so i have this
Code: Select all
private void timer1_Tick(object sender, EventArgs e)
        {
            Point extended = new Point(385, 535);
            Point normal = new Point(417,535);

            if(label1.Location == extended)
            {
                label1.Left += 1;
            }
           
            if (label1.Location == normal)
            {
                label1.Left -= 1;
            }
        }
but it doesnt work

what im trying to do is make the label move back and forth
and i use .left because sources say one can't use .location.X

Re: moving controls at runtime

Posted: Sun Nov 20, 2011 10:16 pm
by M1z23R
Instead of checking if location = point, check if location.X = 417 or location.X = 385

Re: moving controls at runtime

Posted: Sun Nov 20, 2011 10:18 pm
by Axel
Why wouldn't you use label1.location.X ?

And your code is completely wrong, there is only 1 moment where it does move.
I used this way and it worked , tell me if it doesn't
Code: Select all
            Point extended = new Point(385, 535);
            Point normal = new Point(417,535);
            bool x = false;
private void timer1_Tick(object sender, EventArgs e)
        {

            if(label1.Location == extended || label1.Location == normal)
            {
                x = !x;
            }
            if(x)
            {
                label1.Location.X++;
            }else
            { 
                label1.Location.X--;
            }
        }
if it doesn't work , set bool x to true

Re: moving controls at runtime

Posted: Sun Nov 20, 2011 10:59 pm
by Coolblade
Agree with Axel