Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.ComponentModel;
- namespace Cviko7._2 {
- class Polozka{
- public DateTime Datum { get; set; }
- public int Hodnota { get; set; }
- public Polozka(int hodnota)
- {
- Datum = DateTime.Now;
- Hodnota = hodnota;
- }
- public override string ToString()
- {
- return $"{Datum:MM/dd/yyyy} {Hodnota:C}";
- }
- }
- class Program
- {
- [STAThread]
- static void Main(string[] args)
- {
- //pokud chceme velmi rychle pridavat na konec a odebirat od konce pouzijeme tridu stack
- //Stack<int> zasobnik = new Stack<int>;
- BindingList<Polozka> Cisla = new BindingList<Polozka>()
- {
- new Polozka(5), new Polozka(6),new Polozka(7)
- };
- //fronta odebira a uklada na zacatek Queue
- Form form = new Form();
- TableLayoutPanel panel = new TableLayoutPanel();
- panel.AutoSize = true;
- panel.AutoSizeMode = AutoSizeMode.GrowAndShrink;
- panel.Dock = DockStyle.Fill;
- panel.ColumnCount = 3; //pocet sloupců
- panel.RowCount = 3; //pocet radku
- panel.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
- panel.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
- panel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100)); //rozdeleni sloupcu,procentualni rozdeleni
- panel.RowStyles.Add(new RowStyle(SizeType.AutoSize)); //rozdelei radku
- panel.RowStyles.Add(new RowStyle(SizeType.AutoSize)); //rozdelei radku
- panel.RowStyles.Add(new RowStyle(SizeType.Percent, 100));
- panel.CellBorderStyle = TableLayoutPanelCellBorderStyle.Inset;
- NumericUpDown numericUpDown = new NumericUpDown() { DecimalPlaces = 0} ;
- Button buttonpsh = new Button() { Text = "Push" };
- buttonpsh.Click += (sender, e) =>
- {
- int nove = (int)numericUpDown.Value;
- Cisla.Add(new Polozka(nove));
- };
- ListBox list_box_buffer = new ListBox();
- list_box_buffer.Dock = DockStyle.Fill;
- list_box_buffer.DataSource = Cisla;
- BindingSource bs = new BindingSource(Cisla, null);
- DataGridView grid = new DataGridView();
- grid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
- grid.Dock = DockStyle.Fill;
- grid.DataSource = bs;
- grid.AutoGenerateColumns = false;
- DataGridViewTextBoxColumn dtDatum = new DataGridViewTextBoxColumn();
- dtDatum.HeaderText = "Dátum a čas";
- dtDatum.DataPropertyName = nameof(Polozka.Datum);
- dtDatum.DefaultCellStyle.Format = "MM/dd/yyyy HH:mm:ss.fff";
- //hodnota
- DataGridViewTextBoxColumn dtHodnota = new DataGridViewTextBoxColumn();
- dtHodnota.HeaderText = "Hodnota";
- dtHodnota.DataPropertyName = nameof(Polozka.Hodnota) ;
- dtHodnota.DefaultCellStyle.Format = "C";
- grid.Columns.Add(dtDatum);
- grid.Columns.Add(dtHodnota);
- TextBox textBox = new TextBox() { ReadOnly = true };
- Button buttonPop = new Button() { Text = "Pop" };
- buttonPop.Click += (sender, e) =>
- {
- if (Cisla.Count > 0)
- {
- int lastIndex = Cisla.Count - 1;
- Polozka posledni = Cisla[lastIndex];
- Cisla.RemoveAt(lastIndex);
- textBox.Text = posledni.ToString();
- }
- };
- Label radek_navic = new Label() { Text = "Zatim nic" };
- radek_navic.Dock = DockStyle.Fill;
- radek_navic.AutoSize = true;
- bs.Position = 0;
- bs.CurrentItemChanged += (sender, e) => //umoznuje zobrazit v lablu na co jsme klikli
- {
- Polozka aktualni = bs.Current as Polozka;
- if (aktualni != null)
- {
- radek_navic.Text = aktualni.ToString();
- }
- };
- panel.Controls.Add(numericUpDown,0,0); //cisla oznacuji radky,sloupce
- panel.Controls.Add(buttonpsh, 1, 0);
- panel.Controls.Add(grid, 2,0);
- panel.SetRowSpan(grid, 3);
- panel.SetRowSpan(list_box_buffer, 2);
- panel.Controls.Add(textBox, 0, 1);
- panel.Controls.Add(buttonPop, 1, 1);
- panel.Controls.Add(radek_navic, 0, 2);
- panel.SetColumnSpan(radek_navic, 2);
- form.Controls.Add(panel);
- form.Controls.Add(panel);
- Application.EnableVisualStyles();
- Application.Run(form);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement