c# Picturebox
64x64

Abdullah

30.12.2020 00:00:00

 ARKADAŞLAR KODUM BU ŞEKİLDE SIKINTI OLAN DURUM İSE PİCTUREBOXLARIN HEPSİNE FARKLİ SAYI YAZMAM LAZIM SANIRIM BUNUN İÇİN DE PİCTUREBOXLARI AYRIŞTIRMAM LAZIM ŞUAN AYNI İSİMDE ÇIKIYO PİCTUREBOXLAR OYUZDEN HEPSİNE AYNI SAYIYI YAZIYOR YARDIM EDERSENİZ SEVİNİRİM

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)
        {
               
                     
          
        }

        
        
       
    }
}

 

 

Yorum yaz