Cronometro (como somar intervalos de tempo)
19/05/2013
0
namespace WindowsFormsApplication2{ public partial class Form1 : Form { int contUm = 0, contDois = 0; int hor, min, seg; private static TimeSpan tempoTotal = new TimeSpan(); public Form1() { InitializeComponent(); }
private void Form1_Load(object sender, EventArgs e) {
}
private void iniciar(object sender, EventArgs e) { contDois++; if (contDois % 2 == 1) { tempo.Start(); btnIniciar.Text = "Pausar";
} else { tempo.Dispose(); btnIniciar.Text = "Iniciar";
} }
private void parar(object sender, EventArgs e) { tempo.Stop(); contUm = 0; contDois = 0; lblTempo.Text = contUm.ToString() + "0:00:00"; btnIniciar.Text = "Iniciar"; txtTempo.Text = string.Format("{0:#,0#}:{1:#,0#}:{2:#,0#}", hor, min, seg); TimeSpan t = new TimeSpan(); t = TimeSpan.Parse(txtTempo.Text); tempoTotal = TimeSpan.Parse(txtTempo.Text); txtTempo.Text = Convert.ToString(t + tempoTotal); }
private void temp(object sender, EventArgs e) { contUm++; hor = (contUm / 3600); min = (contUm % 3600) / 60; seg = (contUm % 3600) % 60; lblTempo.Text = string.Format("{0:#,0#}:{1:#,0#}:{2:#,0#}", hor, min, seg); }
}}
Vinicius Biá
Posts
19/05/2013
Vinicius Biá
20/05/2013
Pjava
20/05/2013
Vinicius Biá
{
DateTime t_inicio;
DateTime t_fim;
TimeSpan t_diferenca;
if (btnMedir.Text == "Iniciar" )
{
lblDiferenca.Text = "";
t_inicio = DateTime.Now;
btnMedir.Text = "Parar";
}
else
{
t_fim = DateTime.Now;
t_diferenca = t_fim.Subtract(t_inicio);
lblDiferenca.Text = t_diferenca.TotalSeconds.ToString("0.000000") + " segundos";
btnMedir.Text = "Iniciar";
}
}
20/05/2013
Pjava
20/05/2013
Vinicius Biá
20/05/2013
Pjava
DateTime _horaInicio = DateTime.Now;
DateTime _horaFim = Seu_Tempo_Decorrido;
Aí joga num textbox o seguinte:
TimeSpan resultado = _horaFim.Subtract(_horaInicio);
Você então terá sempre a var resultado com o resultado guardado. Depois é só indo acrescentando:
resultado += _horaFim.Subtract(_horaInicio);
Não testei, mas acho que isso funciona.
20/05/2013
Vinicius Biá
20/05/2013
Vinicius Biá
20/05/2013
Pjava
20/05/2013
Vinicius Biá
20/05/2013
Vinicius Biá
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
int contUm = 0, contDois = 0;
int hor, min, seg;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void iniciar(object sender, EventArgs e)
{
contDois++;
if (contDois % 2 == 1)
{
tempo.Start();
btnIniciar.Text = "Pausar";
}
else
{
tempo.Dispose();
btnIniciar.Text = "Iniciar";
}
}
private void parar(object sender, EventArgs e)
{
tempo.Stop();
contUm = 0;
contDois = 0;
lblTempo.Text = contUm.ToString() + "0:00:00";
btnIniciar.Text = "Iniciar";
txtTempo.Text = string.Format("{0:#,0#}:{1:#,0#}:{2:#,0#}", hor, min, seg);
}
private void temp(object sender, EventArgs e)
{
contUm++;
hor = (contUm / 3600);
min = (contUm % 3600) / 60;
seg = (contUm % 3600) % 60;
lblTempo.Text = string.Format("{0:#,0#}:{1:#,0#}:{2:#,0#}", hor, min, seg);
}
}
}
20/05/2013
Pjava
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;
namespace Teste_Hora
{
public partial class Form1 : Form
{
int contUm = 0, contDois = 0;
int hor, min, seg;
private static TimeSpan tempoTotal = new TimeSpan();
int addend1;
int addend2;
int timeLeft;
public Form1()
{
InitializeComponent();
}
private void btnIniciar_Click(object sender, EventArgs e)
{
contDois++;
if (contDois % 2 == 1)
{
tempo.Start();
btnIniciar.Text = "Pausar";
}
else
{
tempo.Dispose();
btnIniciar.Text = "Iniciar";
}
}
private void tempo_Tick(object sender, EventArgs e)
{
timeLeft = timeLeft + 1;
addend1 = timeLeft;
lblTempo.Text = timeLeft + " seconds";
}
private void btnParar_Click(object sender, EventArgs e)
{
tempo.Stop();
contUm = 0;
contDois = 0;
lblTempo.Text = Convert.ToString(addend1);// contUm.ToString() + "0:00:00";
btnIniciar.Text = "Iniciar";
formataHora();
txtTempo.Text = string.Format("{0:#,0#}:{1:#,0#}:{2:#,0#}", hor, min, seg);
TimeSpan t = new TimeSpan();
t = TimeSpan.Parse(txtTempo.Text);
tempoTotal = TimeSpan.Parse(txtTempo.Text);
txtTempo.Text = Convert.ToString(t + tempoTotal);
}
private void formataHora()
{
hor = addend1 / 3600;
min = (addend1 % 3600) / 60;
seg = (addend1 % 3600) % 60;
}
}
}
21/05/2013
Vinicius Biá
Clique aqui para fazer login e interagir na Comunidade :)