moving controls at runtime

Post your questions regarding programming in C# in here.
4 posts Page 1 of 1
Contributors
User avatar
Bogoh67
VIP - Site Partner
VIP - Site Partner
Posts: 656
Joined: Sun Apr 18, 2010 8:20 pm

moving controls at runtime
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
User avatar
M1z23R
VIP - Donator
VIP - Donator
Posts: 622
Joined: Tue Sep 28, 2010 4:55 pm

Re: moving controls at runtime
M1z23R
Instead of checking if location = point, check if location.X = 417 or location.X = 385
User avatar
Axel
Coding God
Coding God
Posts: 1928
Joined: Sun Jun 27, 2010 9:15 pm

Re: moving controls at runtime
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
http://vagex.com/?ref=25000
User avatar
Coolblade
VIP - Site Partner
VIP - Site Partner
Posts: 126
Joined: Mon Oct 24, 2011 7:04 pm

Re: moving controls at runtime
Coolblade
Agree with Axel
http://www.codingpalace.tk/
4 posts Page 1 of 1
Return to “General coding help”