using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.IO;
namespace paint1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Point posicionPrevia = new Point(-1, -1);
private void canvas_MouseMove(object sender, MouseEventArgs e)
{
if (posicionPrevia.X == -1)
{
posicionPrevia = new Point(e.X, e.Y);
}
Point posicionActual = new Point(e.X, e.Y);
Graphics dibujo = canvas.CreateGraphics();
dibujo.SmoothingMode = SmoothingMode.None;
if (e.Button == MouseButtons.Left)
{
// Para permitir dibujar no debe de salirse del recuadro.
if ((e.X >= 0 && e.X <= this.canvas.Size.Width) && (e.Y >= 0 && e.Y <= this.canvas.Height))
{
dibujo.DrawLine(new Pen(Color.Blue, 2),
posicionPrevia, posicionActual);
// Grabar el dato en el textbox
var MyFecha_tmp = new DateTime(Convert.ToInt32(tb_FI.Text.Substring(0, 4)), Convert.ToInt32(tb_FI.Text.Substring(5, 2)), Convert.ToInt32(tb_FI.Text.Substring(8, 2)), Convert.ToInt32(tb_FI.Text.Substring(11, 2)), Convert.ToInt32(tb_FI.Text.Substring(14, 2)), 0, DateTimeKind.Utc);
MyFecha_tmp = MyFecha_tmp.AddMinutes(e.X);
decimal ymin, ymax, ydif;
ymin = Convert.ToDecimal(tb_ymin.Text);
ymax = Convert.ToDecimal(tb_ymax.Text);
ydif = 280 / (ymax - ymin);
if (posicionPrevia.X != posicionActual.X)
{
textBox1.Text = textBox1.Text + MyFecha_tmp.ToString("yyyy-MM-dd HH:mm:ss").ToString() + " " + (((280 - e.Y) / ydif) + ymin).ToString("####0.####").ToString() + String.Format(Environment.NewLine);
//textBox1.Select(textBox1.Text.Length, 0);
textBox1.SelectionStart = textBox1.Text.Length;
textBox1.ScrollToCaret();
}
}
}
posicionPrevia = posicionActual;
if ((e.X >= 0 && e.X < this.canvas.Size.Width) && (e.Y >= 0 && e.Y < this.canvas.Height))
{
labelx.Text = e.X.ToString();
labely.Text = e.Y.ToString();
var MyFecha_tmp = new DateTime(Convert.ToInt32(tb_FI.Text.Substring(0, 4)), Convert.ToInt32(tb_FI.Text.Substring(5, 2)), Convert.ToInt32(tb_FI.Text.Substring(8, 2)), Convert.ToInt32(tb_FI.Text.Substring(11, 2)), Convert.ToInt32(tb_FI.Text.Substring(14, 2)), 0, DateTimeKind.Utc);
MyFecha_tmp = MyFecha_tmp.AddMinutes(e.X);
label1.Text = MyFecha_tmp.ToString("yyyy-MM-dd HH:mm:ss").ToString();
decimal ymin, ymax, ydif;
ymin = Convert.ToDecimal(tb_ymin.Text);
ymax = Convert.ToDecimal(tb_ymax.Text);
ydif = 280 / (ymax - ymin);
label2.Text = (((280 - e.Y) / ydif) + ymin).ToString("####0.####").ToString();
}
}
private void button1_Click(object sender, EventArgs e)
{
decimal ymin, ymax, ytmp;
ymin = 0;
ymax = 0;
StreamReader sr = new StreamReader("TestFile.txt");
String line = sr.ReadLine();
tb_FI.Text = line.Substring(0,16);
ymin = Convert.ToDecimal(line.Substring(20,line.Length-20).ToString());
ymax = ymin;
while (line != null)
{
ytmp = Convert.ToDecimal(line.Substring(20, line.Length - 20).ToString());
if (ytmp < ymin) ymin = ytmp;
if (ytmp > ymax) ymax = ytmp;
tb_FF.Text = line.Substring(0,16);
line = sr.ReadLine();
}
tb_ymin.Text = ymin.ToString();
tb_ymax.Text = ymax.ToString();
this.canvas.Enabled = true;
this.button4.Enabled = true;
this.button2.Enabled = true;
}
private void canvas_MouseUp(object sender, MouseEventArgs e)
{
}
private void canvas_MouseDown(object sender, MouseEventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
//
// Calcular el ancho del objeto picture
//
var MyFechaI = new DateTime(Convert.ToInt32(tb_FI.Text.Substring(0, 4)), Convert.ToInt32(tb_FI.Text.Substring(5, 2)), Convert.ToInt32(tb_FI.Text.Substring(8, 2)), Convert.ToInt32(tb_FI.Text.Substring(11, 2)), Convert.ToInt32(tb_FI.Text.Substring(14, 2)), 0, DateTimeKind.Utc);
var MyFechaF = new DateTime(Convert.ToInt32(tb_FF.Text.Substring(0, 4)), Convert.ToInt32(tb_FF.Text.Substring(5, 2)), Convert.ToInt32(tb_FF.Text.Substring(8, 2)), Convert.ToInt32(tb_FF.Text.Substring(11, 2)), Convert.ToInt32(tb_FF.Text.Substring(14, 2)), 0, DateTimeKind.Utc);
var MyFecha_tmp = new DateTime(Convert.ToInt32(tb_FF.Text.Substring(0, 4)), Convert.ToInt32(tb_FF.Text.Substring(5, 2)), Convert.ToInt32(tb_FF.Text.Substring(8, 2)), Convert.ToInt32(tb_FF.Text.Substring(11, 2)), Convert.ToInt32(tb_FF.Text.Substring(14, 2)), 0, DateTimeKind.Utc);
decimal ymin, ymax, ytmp, ydif;
ymin = Convert.ToDecimal(tb_ymin.Text);
ymax = Convert.ToDecimal(tb_ymax.Text);
ydif = 280/(ymax - ymin);
TimeSpan t = MyFechaF.ToUniversalTime() - MyFechaI.ToUniversalTime();
//
// Cambiar tamaño al objeto picture
//
this.canvas.Size = new System.Drawing.Size(Convert.ToInt32(t.TotalMinutes + 1), 281);
//textBox1.Text = "WIDTH: " + (t.TotalMinutes) + " MyFechaF:" + MyFechaF.ToUniversalTime().ToString() + " MyFechaI:" + MyFechaI.ToUniversalTime().ToString() + " size " + this.canvas.Size.Width + " " + this.canvas.Size.Height;
Point posicionPrevia_tmp = new Point(-1, -1);
StreamReader sr = new StreamReader("TestFile.txt");
String line = sr.ReadLine();
while (line != null)
{
// Obtener X
MyFecha_tmp = new DateTime(Convert.ToInt32(line.Substring(0, 4)), Convert.ToInt32(line.Substring(5, 2)), Convert.ToInt32(line.Substring(8, 2)), Convert.ToInt32(line.Substring(11, 2)), Convert.ToInt32(line.Substring(14, 2)), 0, DateTimeKind.Utc);
t = MyFecha_tmp.ToUniversalTime() - MyFechaI.ToUniversalTime(); //new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
// Obtener Y
ytmp = Convert.ToDecimal(line.Substring(20, line.Length - 20).ToString());
// Graficar.
if (posicionPrevia_tmp.X == -1)
{
posicionPrevia_tmp = new Point(Convert.ToInt32(t.TotalMinutes), 281-Convert.ToInt32(((ytmp - ymin) * ydif+1))); // No se si se deba sumar una unidad +1 (debo de analizar)
}
Point posicionActual_tmp = new Point(Convert.ToInt32(t.TotalMinutes), 281-Convert.ToInt32(((ytmp - ymin) * ydif+1)));
Graphics dibujo = canvas.CreateGraphics();
//Graphics dibujo = Graphics.FromHwnd(this.Handle);
dibujo.SmoothingMode = SmoothingMode.None;
dibujo.DrawLine(new Pen(Color.Black), posicionPrevia_tmp, posicionActual_tmp);
posicionPrevia_tmp = posicionActual_tmp;
line = sr.ReadLine();
}
}
private void button3_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void button4_Click(object sender, EventArgs e)
{
//
// Calcular el ancho del objeto picture
//
var MyFechaI = new DateTime(Convert.ToInt32(tb_FI.Text.Substring(0, 4)), Convert.ToInt32(tb_FI.Text.Substring(5, 2)), Convert.ToInt32(tb_FI.Text.Substring(8, 2)), Convert.ToInt32(tb_FI.Text.Substring(11, 2)), Convert.ToInt32(tb_FI.Text.Substring(14, 2)), 0, DateTimeKind.Utc);
var MyFechaF = new DateTime(Convert.ToInt32(tb_FF.Text.Substring(0, 4)), Convert.ToInt32(tb_FF.Text.Substring(5, 2)), Convert.ToInt32(tb_FF.Text.Substring(8, 2)), Convert.ToInt32(tb_FF.Text.Substring(11, 2)), Convert.ToInt32(tb_FF.Text.Substring(14, 2)), 0, DateTimeKind.Utc);
var MyFecha_tmp = new DateTime(Convert.ToInt32(tb_FF.Text.Substring(0, 4)), Convert.ToInt32(tb_FF.Text.Substring(5, 2)), Convert.ToInt32(tb_FF.Text.Substring(8, 2)), Convert.ToInt32(tb_FF.Text.Substring(11, 2)), Convert.ToInt32(tb_FF.Text.Substring(14, 2)), 0, DateTimeKind.Utc);
TimeSpan t = MyFechaF.ToUniversalTime() - MyFechaI.ToUniversalTime();
//
// Cambiar tamaño al objeto picture
//
this.canvas.Size = new System.Drawing.Size(Convert.ToInt32(t.TotalMinutes + 1), 281);
this.canvas.Image = null;
textBox1.Text = "";
}
}
}