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

namespace Analyzator_01
{
    public partial class Meritko : UserControl
    {
        private double _Cas = 0; 

        public double Cas
        {
            get { return _Cas; }
            set { _Cas = value; Invalidate(); }
        }

        public Meritko(/*double vz*/)
        {
            InitializeComponent();
            //this.vzorkovani = vz; 

            SetStyle(ControlStyles.ResizeRedraw, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            //base.OnPaint(e);
            e.Graphics.FillRectangle(Brushes.White, ClientRectangle);

            /*
            double vzorkovani = GlobalniPromene.Vzorkovani;
            double k = Width / (_Cas * vzorkovani);
            double M = 1 / vzorkovani;
            */
            
            for (int i = 0; i < 5; i++)
            {
                //e.Graphics.DrawRectangle(Pens.Black, i * Width / 5, 0, Width / 10, Height - 1);
                e.Graphics.FillRectangle(Brushes.Black, i * Width / 5, (Height/2) , Width / 10, Height/2-1);
            }
            e.Graphics.DrawLine(Pens.Black, 0, Height / 2, Width, Height / 2);
            /*
            for (int i = 0; i < 10; i++)
            {
            //for (int i = 0; i < 10; i++)
                e.Graphics.DrawString(i.ToString(), SystemFonts.DefaultFont, Brushes.Black, i * Width / 10, 0, new StringFormat() { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Near });
            }
            */

            if (_Cas >= 1)
            {
                for (int i = 0; i < 10; i++)
                    e.Graphics.DrawString((i*_Cas/10).ToString("0.##"), SystemFonts.DefaultFont, Brushes.Black, i * Width / 10, 0, new StringFormat() { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Near });
                e.Graphics.DrawString("s", SystemFonts.DefaultFont, Brushes.Black, Width, 0, new StringFormat() { Alignment = StringAlignment.Far, LineAlignment = StringAlignment.Near });
            }
            else if (_Cas * 1000 >= 1)
            {
                for (int i = 0; i < 10; i++)
                    e.Graphics.DrawString((i * _Cas / 10 * 1000).ToString("0.##"), SystemFonts.DefaultFont, Brushes.Black, i * Width / 10, 0, new StringFormat() { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Near });
                e.Graphics.DrawString("ms", SystemFonts.DefaultFont, Brushes.Black, Width, 0, new StringFormat() { Alignment = StringAlignment.Far, LineAlignment = StringAlignment.Near });
            }
            else if (_Cas * 1000 * 1000 >= 1)
            {
                for (int i = 0; i < 10; i++)
                    e.Graphics.DrawString((i * _Cas / 10 * 1000 * 1000).ToString("0.##"), SystemFonts.DefaultFont, Brushes.Black, i * Width / 10, 0, new StringFormat() { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Near });
                e.Graphics.DrawString("us", SystemFonts.DefaultFont, Brushes.Black, Width, 0, new StringFormat() { Alignment = StringAlignment.Far, LineAlignment = StringAlignment.Near });
            }
            else if (_Cas * 1000 * 1000 * 1000 >= 1)
            {
                for (int i = 0; i < 10; i++)
                    e.Graphics.DrawString((i * _Cas / 10 * 1000 * 1000 * 1000).ToString("0.##"), SystemFonts.DefaultFont, Brushes.Black, i * Width / 10, 0, new StringFormat() { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Near });
                e.Graphics.DrawString("ns", SystemFonts.DefaultFont, Brushes.Black, Width, 0, new StringFormat() { Alignment = StringAlignment.Far, LineAlignment = StringAlignment.Near });
            }
            else if (_Cas * 1000 * 1000 * 1000 * 1000 >= 1)
            {
                for (int i = 0; i < 10; i++)
                    e.Graphics.DrawString((i * _Cas / 10 * 1000 * 1000 * 1000 * 1000).ToString("0.##"), SystemFonts.DefaultFont, Brushes.Black, i * Width / 10, 0, new StringFormat() { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Near });
                e.Graphics.DrawString("ps", SystemFonts.DefaultFont, Brushes.Black, Width, 0, new StringFormat() { Alignment = StringAlignment.Far, LineAlignment = StringAlignment.Near });
            }

            
                

        }
    }
}
