Subversion Repositories general

Compare Revisions

Ignore whitespace Rev 1413 → Rev 1414

//akStopWatch/trunk/MainForm.cs
0,0 → 1,86
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
 
namespace akStopWatch
{
public partial class MainForm : Form
{
private int time = 0;
 
public MainForm()
{
InitializeComponent();
}
 
private void MainForm_Click(object sender, EventArgs e)
{
Start();
}
 
private void MainForm_KeyPress(object sender, KeyPressEventArgs e)
{
Start();
}
 
private void MainForm_Load(object sender, EventArgs e)
{
Start();
}
 
private void MainForm_Resize(object sender, EventArgs e)
{
}
 
private void timer_Tick(object sender, EventArgs e)
{
++time;
ShowTime();
}
 
private void Start()
{
timer.Stop();
time = 0;
ShowTime();
timer.Start();
}
 
private void ShowTime()
{
timeLabel.Refresh();
}
 
private void timeLabel_Paint(object sender, PaintEventArgs e)
{
try
{
Graphics g = e.Graphics;
SolidBrush brush = new SolidBrush(Color.Black);
 
g.FillRectangle(SystemBrushes.Control, g.Clip.GetBounds(g));
 
int hour = time / 60 / 60;
int min = time / 60 % 60;
int sec = time % 60 % 60;
string str = string.Format("{0:00}:{1:00}:{2:00}", hour, min, sec);
 
SizeF strSize = g.MeasureString(str, timeLabel.Font);
float k = Math.Min(timeLabel.Width / strSize.Width, timeLabel.Height / strSize.Height);
float x = (timeLabel.Width - strSize.Width * k) / 2;
float y = (timeLabel.Height - strSize.Height * k) / 2;
Font font = new Font(timeLabel.Font.FontFamily, timeLabel.Font.Size * k, timeLabel.Font.Style);
g.DrawString(str, font, brush, x, y);
}
catch(Exception ex)
{
Console.WriteLine(ex.Message + "\n" + ex.StackTrace);
}
}
}
}