Advertisement
bartigames

C# listy

Mar 18th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.88 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.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.IO;
  11.  
  12. namespace WindowsFormsApplication2
  13. {
  14.     public partial class Form1 : Form
  15.     {
  16.         public Form1()
  17.         {
  18.             InitializeComponent();
  19.         }
  20.  
  21.         private void button1_Click(object sender, EventArgs e)
  22.         {
  23.  
  24.             int ILE;
  25.             Random r = new Random();
  26.  
  27.             lista1.Items.Clear();
  28.  
  29.  
  30.             ILE = r.Next(5, 20);
  31.  
  32.             for (int i = 0; i < ILE; i++)
  33.             {
  34.                 lista1.Items.Add(r.Next(100));
  35.             }
  36.  
  37.  
  38.  
  39.  
  40.         }
  41.  
  42.         private void button2_Click(object sender, EventArgs e)
  43.         {
  44.  
  45.             int min = Convert.ToInt32((lista1.Items[0]));
  46.             int lenght = lista1.Items.Count;
  47.  
  48.             for (int i = 0; i < lenght; i++)
  49.             {
  50.  
  51.               int value = Convert.ToInt32(lista1.Items[i]);
  52.  
  53.  
  54.               if (value < min)
  55.               {
  56.                   min = value;
  57.                  
  58.               }
  59.  
  60.             }
  61.             lista1.SelectedItem = min;
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.         }
  73.  
  74.         private void button3_Click(object sender, EventArgs e)
  75.         {
  76.             if (openFileDialog1.ShowDialog() == DialogResult.OK)
  77.             {
  78.                 string linia;
  79.                 lista1.Items.Clear();
  80.                 FileInfo plik = new FileInfo(openFileDialog1.FileName);
  81.                
  82.                 StreamReader p = plik.OpenText();
  83.  
  84.                 while((linia = p.ReadLine()) != null){
  85.  
  86.                     lista1.Items.Add(linia);
  87.  
  88.                 }
  89.             }
  90.         }
  91.  
  92.         private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
  93.         {
  94.  
  95.         }
  96.     }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement