Advertisement
ntamas

140407

Apr 7th, 2014
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.98 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace _20140407
  11. {
  12.   public partial class Form1 : Form
  13.   {
  14.     public Form1()
  15.     {
  16.       InitializeComponent();
  17.     }
  18.     private bool paritas(int szam)
  19.     {
  20.       if (szam % 2 == 0)
  21.       {
  22.         return true;
  23.       }
  24.       else
  25.       {
  26.         return false;
  27.       }
  28.    
  29.     }
  30.     private void button1_Click(object sender, EventArgs e)
  31.     {
  32.       if(textBox1.Text != "" && textBox2.Text != "")
  33.       {
  34.         int min, max, rnd, db = 0, cs;
  35.         min = Convert.ToInt32(textBox1.Text);
  36.         max = Convert.ToInt32(textBox2.Text);
  37.         if (min > max)
  38.         {
  39.           cs = min;
  40.           min = max;
  41.           max = cs;
  42.         }
  43.         Random vel = new Random();
  44.         listBox1.Items.Clear();
  45.         db = 0;
  46.         if (checkBox1.Checked && checkBox2.Checked)
  47.         {
  48.           for (int i = 0; i < 10; i++)
  49.           {
  50.             rnd = vel.Next(min, max + 1);
  51.             listBox1.Items.Add(rnd);
  52.           }
  53.         }
  54.         else if (checkBox1.Checked && !checkBox2.Checked)
  55.         {
  56.           do
  57.           {
  58.             rnd = vel.Next(min, max + 1);
  59.             if(paritas(rnd))
  60.             {
  61.               listBox1.Items.Add(rnd);
  62.               db++;
  63.             }
  64.           }while(db < 10);
  65.         }
  66.         else if (!checkBox1.Checked && checkBox2.Checked)
  67.         {
  68.           do
  69.           {
  70.             rnd = vel.Next(min, max + 1);
  71.             if (!paritas(rnd))
  72.             {
  73.               listBox1.Items.Add(rnd);
  74.               db++;
  75.             }
  76.           } while (db < 10);
  77.         }
  78.       }
  79.     }
  80.     private void duplaklikk(object sender, EventArgs e)
  81.     {
  82.       listBox1.Items.Remove(listBox1.SelectedItem);
  83.     }
  84.     private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
  85.     {
  86.      
  87.     }
  88.   }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement