1 svar
58 visningar
Shali_47 är nöjd med hjälpen
Shali_47 263
Postad: 7 aug 2023 21:06 Redigerad: 7 aug 2023 21:07

Fält med Objekt

 

Hej när jag försöker skriva denna kod så får jag ingen respons kan ni guida tack!

namespace Projekt { 

    class Program
    {
        static void Main(string[] args)
        {
        


        }
    }



    public partial class Form01_01 : Form
    {
        public Form01_01()
        {
            InitializeComponent();

            // Create an array of PictureBox controls.
            PictureBox[] bilder = new PictureBox[25]; // 5 rows x 5 columns
            int x = 0, y = 0, width = 50, height = 50;

            // Set the position and dimensions for the first PictureBox.
            for (int i = 0; i < bilder.Length; i++)
            {
                bilder[i] = new PictureBox();
                bilder[i].Left = x;
                bilder[i].Top = y;
                bilder[i].Width = width;
                bilder[i].Height = height;
                bilder[i].BackgroundImage = Image.FromFile("Blomma.png");
                bilder[i].Click += pbxBlomma_Click;

                this.Controls.Add(bilder[i]);

                x += width;

                // Move to the next row after each row of PictureBoxes.
                if ((i + 1) % 5 == 0)
                {
                    x = 0;
                    y += height;
                }
            }
        }

        private void pbxBlomma_Click(object sender, EventArgs e)
        {
            PictureBox klickadBlomma = (PictureBox)sender;
            klickadBlomma.BorderStyle = BorderStyle.FixedSingle;
        }
    }
}
Tegelhus 225
Postad: 8 aug 2023 22:56

Programmet börjar alltid i din main-funktion. Eftersom den är tom körs inget. Du har ju andra funktioner men de kommer alltså aldrig att anropas och därmed aldrig köras.

Svara Avbryt
Close