C# picturebox ayrı yazı nasıl yazılır?

Elcl0wn

Centipat
Katılım
26 Ocak 2020
Mesajlar
2
Arkadaşlar kodum bu şekilde sıkıntı olan durum ise pictureboxların hepsine farklı sayı yazmaması.
Eğere picturboxları ayrıştıracak hepsine ayrı yazı yazmamı sağlayacak kod varsa ve ya başka bir yerde yanlışım varsa yazabilirsiniz yardım bekliyorum (kodun amacı ekrana 4 tane rastgele şık geliyor 1 tane işlen doğru bilince +1 puan )







C#:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Proje
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
           
        }
        int sayac = 0;
        static Random _random = new Random();
        static void Shuffle<T>(T[] array)
        {
            int n = array.Length;
            for (int i = 0; i < n; i++)
            {

                int r = i + (int)(_random.NextDouble() * (n - i));
                T t = array[r];
                array[r] = array[i];
                array[i] = t;
            }
        }
        int sayı;
        int[] sayılar = new int[4];
        string[] islemler = new string[] { "+", "*", "-" };
        Random rnd1 = new Random();
        int sorus1, sorus2, hislem;
        int rastsayı;
        string[] pictureler = new string[] { "yesil", "kırmızı", "mor", "mavi" };
        Random rnd = new Random();
        private void button1_Click(object sender, EventArgs e)
        {
            hislem = rnd.Next(0, 3);
            sorus1 = rnd.Next(0, 10);
            sorus2 = rnd.Next(0, 10);
            panel1.Controls.Clear();
            soruolustur();
            Shuffle(pictureler);

            for (int i = 0; i < 4; i++)
            {
                sayac++;
                sayı = rnd.Next(0, 11);
                picolustur(200 * i, pictureler[i]);
               
            }
            benzersizrast();
         

        }
        public void soruolustur()
        {
            PictureBox pic_box = new PictureBox();
            pic_box.SetBounds(280, 240, 150, 150);
            pic_box.ImageLocation = "turuncu.png";
            pic_box.SizeMode = PictureBoxSizeMode.StretchImage;
            panel1.Controls.Add(pic_box);
            pic_box.Paint += Pic_box_Paint;
         
        }

        private void Pic_box_Paint(object sender, PaintEventArgs e)
        {
            using (Font myFont = new Font("Ariel", 20))
            {

                e.Graphics.DrawString(sorus1+islemler[hislem]+sorus2, myFont, Brushes.Black, new Point(45, 65));

            }
        }
       
        public void picolustur(int x,string z)
        {
           
            for (int i = 0; i < 4; i++)
            {
               
                PictureBox picbox = new PictureBox();
                picbox.SetBounds(x, 40, 150, 150);
                picbox.ImageLocation = z + ".png";
                picbox.SizeMode = PictureBoxSizeMode.StretchImage;
                panel1.Controls.Add(picbox);
                picbox.Name = sayac.ToString();
                picbox.Paint += Picbox_Paint;
                picbox.Click += Picbox_Click;
               
            }
           
        }

        private void Picbox_Paint(object sender, PaintEventArgs e)
        {
           
       
            using (Font myFont = new Font("Ariel", 20))
            {

                e.Graphics.DrawString(sayılar[1].ToString(), myFont, Brushes.Black, new Point(55, 65));

            }
        }
       
        public void benzersizrast()
        {
            int sayac = 0;
            while (sayac < 4)
            {
                rastsayı = rnd.Next(1, 10);
                if (Array.IndexOf(sayılar, rastsayı) == -1)
                {
                    sayılar[sayac] = rastsayı;
                    sayac++;
                }
            }
        }
        private void Picbox_Click(object sender, EventArgs e)
        {
           
        }

        private void Form1_Load(object sender, EventArgs e)
        {
             
                   
         
        }

       
       
     
    }
}
 

Dosya Ekleri

  • 1609295982589.gif
    43 bayt · Görüntüleme: 51
  • 1609295982530.gif
    43 bayt · Görüntüleme: 49
  • 1609296176349.gif
    43 bayt · Görüntüleme: 34
  • 1609296176291.gif
    43 bayt · Görüntüleme: 42
Son düzenleyen: Moderatör:
Bu siteyi kullanmak için çerezler gereklidir. Siteyi kullanmaya devam etmek için çerezleri kabul etmelisiniz. Daha Fazlasını Öğren.…