Nie mogę ustawić pozycji picturebox.

0

Szybkie pytanko. Dlaczego to nie działa? Nie wiem czy dobrze rozumiem. Pisze że to nie jest zmienna? Ale to jest przecie zmienna! Tak?
Nie ogarniam proszę niech ktoś mi to wytłumaczy. (Luknijcie na załącznik)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
//using System.Drawing;

namespace Kucykowe_Igrzyska
{
    class Greyhound
    {
       // PictureBox[] kucyki = new PictureBox[4];
        //PictureBox[]kucyki = { rainbow
        //Kucyki[] kucyki = new Kucyki[4];
       // public PictureBox[] kucyk; //= new PictureBox[4];
        

        public PictureBox red;
      
        public bool Zapieprzaj = true;
      
        public int sprawdzam = 1;
        public Timer clock;
        public Random Randomizer;
        int[] losuj = { 10, 20, 30, 40 };
        

        public void TakeStartingPosition()
        {
           // MessageBox.Show(""+red.Location.X);
           if (red.Location.X != 15)
            {
                red.Location.X = 15;
               
              //  red.Location = new Point(15,red.Location.Y) ;
            }
            //red.Location.X = sprawdzam;
        }



        public void Move()
        {
           // Randomizer = new Random();
            if (red != null)
            {
                if (Zapieprzaj == true)
                {
                    red.Left += losuj[Randomizer.Next(losuj.Length)];
                    if (red.Left >= red.Parent.Width - red.Width)
                    {
                        Zapieprzaj = false;
                        MessageBox.Show(red.Name);
                    }
                }
                else
                {
         

                    clock.Enabled = false;

                  //  clock.Enabled = false;
                   /* red.Left -= 10;
                    if (red.Left <= 0)
                    {
                        Zapieprzaj = true;
                    }*/
                }
            }
            /*  public int StartingPosition;
              public int RacetrackLength;
              public PictureBox myPictureBox = null;
              public int Location = 0;
              public Random MyRandom;

              public bool Run()
              {

              }
              public void TakeStartingPosition()
              {

              } */
        }
    }
} 
0

Może spróbuj tak, jak jest napisane na msdn?

Because the Point class is a value type (Structure in Visual Basic, struct in Visual C#), it is returned by value, meaning accessing the property returns a copy of the upper-left point of the control.So, adjusting the X or Y properties of the Point returned from this property will not affect the Left, Right, Top, or Bottom property values of the control.To adjust these properties set each property value individually, or set the Location property with a new Point.

Czyli: red.Location.Left = ... lub po prostu new Point

0

Chyba rozumiem. Dzięki.

1 użytkowników online, w tym zalogowanych: 0, gości: 1