/akStopWatch/trunk/SettingsForm.resx |
---|
0,0 → 1,120 |
<?xml version="1.0" encoding="utf-8"?> |
<root> |
<!-- |
Microsoft ResX Schema |
Version 2.0 |
The primary goals of this format is to allow a simple XML format |
that is mostly human readable. The generation and parsing of the |
various data types are done through the TypeConverter classes |
associated with the data types. |
Example: |
... ado.net/XML headers & schema ... |
<resheader name="resmimetype">text/microsoft-resx</resheader> |
<resheader name="version">2.0</resheader> |
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> |
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> |
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data> |
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data> |
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> |
<value>[base64 mime encoded serialized .NET Framework object]</value> |
</data> |
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> |
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> |
<comment>This is a comment</comment> |
</data> |
There are any number of "resheader" rows that contain simple |
name/value pairs. |
Each data row contains a name, and value. The row also contains a |
type or mimetype. Type corresponds to a .NET class that support |
text/value conversion through the TypeConverter architecture. |
Classes that don't support this are serialized and stored with the |
mimetype set. |
The mimetype is used for serialized objects, and tells the |
ResXResourceReader how to depersist the object. This is currently not |
extensible. For a given mimetype the value must be set accordingly: |
Note - application/x-microsoft.net.object.binary.base64 is the format |
that the ResXResourceWriter will generate, however the reader can |
read any of the formats listed below. |
mimetype: application/x-microsoft.net.object.binary.base64 |
value : The object must be serialized with |
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter |
: and then encoded with base64 encoding. |
mimetype: application/x-microsoft.net.object.soap.base64 |
value : The object must be serialized with |
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter |
: and then encoded with base64 encoding. |
mimetype: application/x-microsoft.net.object.bytearray.base64 |
value : The object must be serialized into a byte array |
: using a System.ComponentModel.TypeConverter |
: and then encoded with base64 encoding. |
--> |
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> |
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> |
<xsd:element name="root" msdata:IsDataSet="true"> |
<xsd:complexType> |
<xsd:choice maxOccurs="unbounded"> |
<xsd:element name="metadata"> |
<xsd:complexType> |
<xsd:sequence> |
<xsd:element name="value" type="xsd:string" minOccurs="0" /> |
</xsd:sequence> |
<xsd:attribute name="name" use="required" type="xsd:string" /> |
<xsd:attribute name="type" type="xsd:string" /> |
<xsd:attribute name="mimetype" type="xsd:string" /> |
<xsd:attribute ref="xml:space" /> |
</xsd:complexType> |
</xsd:element> |
<xsd:element name="assembly"> |
<xsd:complexType> |
<xsd:attribute name="alias" type="xsd:string" /> |
<xsd:attribute name="name" type="xsd:string" /> |
</xsd:complexType> |
</xsd:element> |
<xsd:element name="data"> |
<xsd:complexType> |
<xsd:sequence> |
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> |
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> |
</xsd:sequence> |
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> |
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> |
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> |
<xsd:attribute ref="xml:space" /> |
</xsd:complexType> |
</xsd:element> |
<xsd:element name="resheader"> |
<xsd:complexType> |
<xsd:sequence> |
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> |
</xsd:sequence> |
<xsd:attribute name="name" type="xsd:string" use="required" /> |
</xsd:complexType> |
</xsd:element> |
</xsd:choice> |
</xsd:complexType> |
</xsd:element> |
</xsd:schema> |
<resheader name="resmimetype"> |
<value>text/microsoft-resx</value> |
</resheader> |
<resheader name="version"> |
<value>2.0</value> |
</resheader> |
<resheader name="reader"> |
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> |
</resheader> |
<resheader name="writer"> |
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> |
</resheader> |
</root> |
/akStopWatch/trunk/akStopWatch.csproj |
---|
53,6 → 53,10 |
<LastGenOutput>Resources.Designer.cs</LastGenOutput> |
<SubType>Designer</SubType> |
</EmbeddedResource> |
<EmbeddedResource Include="SettingsForm.resx"> |
<SubType>Designer</SubType> |
<DependentUpon>SettingsForm.cs</DependentUpon> |
</EmbeddedResource> |
<Compile Include="Properties\Resources.Designer.cs"> |
<AutoGen>True</AutoGen> |
<DependentUpon>Resources.resx</DependentUpon> |
66,6 → 70,12 |
<DependentUpon>Settings.settings</DependentUpon> |
<DesignTimeSharedInput>True</DesignTimeSharedInput> |
</Compile> |
<Compile Include="SettingsForm.cs"> |
<SubType>Form</SubType> |
</Compile> |
<Compile Include="SettingsForm.Designer.cs"> |
<DependentUpon>SettingsForm.cs</DependentUpon> |
</Compile> |
</ItemGroup> |
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> |
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. |
/akStopWatch/trunk/SettingsForm.Designer.cs |
---|
0,0 → 1,123 |
namespace akStopWatch |
{ |
partial class SettingsForm |
{ |
/// <summary> |
/// Required designer variable. |
/// </summary> |
private System.ComponentModel.IContainer components=null; |
/// <summary> |
/// Clean up any resources being used. |
/// </summary> |
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> |
protected override void Dispose(bool disposing) |
{ |
if(disposing&&(components!=null)) |
{ |
components.Dispose(); |
} |
base.Dispose(disposing); |
} |
#region Windows Form Designer generated code |
/// <summary> |
/// Required method for Designer support - do not modify |
/// the contents of this method with the code editor. |
/// </summary> |
private void InitializeComponent() |
{ |
this.countLabel=new System.Windows.Forms.Label(); |
this.okButton=new System.Windows.Forms.Button(); |
this.cancelButton=new System.Windows.Forms.Button(); |
this.countBox=new System.Windows.Forms.NumericUpDown(); |
((System.ComponentModel.ISupportInitialize)(this.countBox)).BeginInit(); |
this.SuspendLayout(); |
// |
// countLabel |
// |
this.countLabel.AutoSize=true; |
this.countLabel.Location=new System.Drawing.Point(12, 9); |
this.countLabel.Name="countLabel"; |
this.countLabel.Size=new System.Drawing.Size(100, 13); |
this.countLabel.TabIndex=0; |
this.countLabel.Text="Number of counters"; |
// |
// okButton |
// |
this.okButton.Anchor=((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom|System.Windows.Forms.AnchorStyles.Right))); |
this.okButton.DialogResult=System.Windows.Forms.DialogResult.OK; |
this.okButton.Location=new System.Drawing.Point(124, 36); |
this.okButton.Name="okButton"; |
this.okButton.Size=new System.Drawing.Size(75, 23); |
this.okButton.TabIndex=2; |
this.okButton.Text="OK"; |
this.okButton.UseVisualStyleBackColor=true; |
// |
// cancelButton |
// |
this.cancelButton.Anchor=((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom|System.Windows.Forms.AnchorStyles.Right))); |
this.cancelButton.DialogResult=System.Windows.Forms.DialogResult.Cancel; |
this.cancelButton.Location=new System.Drawing.Point(205, 36); |
this.cancelButton.Name="cancelButton"; |
this.cancelButton.Size=new System.Drawing.Size(75, 23); |
this.cancelButton.TabIndex=3; |
this.cancelButton.Text="Cancel"; |
this.cancelButton.UseVisualStyleBackColor=true; |
// |
// countBox |
// |
this.countBox.Anchor=((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top|System.Windows.Forms.AnchorStyles.Left) |
|System.Windows.Forms.AnchorStyles.Right))); |
this.countBox.Location=new System.Drawing.Point(124, 7); |
this.countBox.Maximum=new decimal(new int[] { |
10, |
0, |
0, |
0}); |
this.countBox.Minimum=new decimal(new int[] { |
1, |
0, |
0, |
0}); |
this.countBox.Name="countBox"; |
this.countBox.Size=new System.Drawing.Size(156, 20); |
this.countBox.TabIndex=4; |
this.countBox.Value=new decimal(new int[] { |
1, |
0, |
0, |
0}); |
// |
// SettingsForm |
// |
this.AcceptButton=this.okButton; |
this.AutoScaleDimensions=new System.Drawing.SizeF(6F, 13F); |
this.AutoScaleMode=System.Windows.Forms.AutoScaleMode.Font; |
this.CancelButton=this.cancelButton; |
this.ClientSize=new System.Drawing.Size(292, 71); |
this.Controls.Add(this.countBox); |
this.Controls.Add(this.cancelButton); |
this.Controls.Add(this.okButton); |
this.Controls.Add(this.countLabel); |
this.FormBorderStyle=System.Windows.Forms.FormBorderStyle.FixedDialog; |
this.MaximizeBox=false; |
this.MinimizeBox=false; |
this.Name="SettingsForm"; |
this.StartPosition=System.Windows.Forms.FormStartPosition.CenterParent; |
this.Text="akStopWatch - Settings"; |
((System.ComponentModel.ISupportInitialize)(this.countBox)).EndInit(); |
this.ResumeLayout(false); |
this.PerformLayout(); |
} |
#endregion |
private System.Windows.Forms.Label countLabel; |
private System.Windows.Forms.Button okButton; |
private System.Windows.Forms.Button cancelButton; |
public System.Windows.Forms.NumericUpDown countBox; |
} |
} |
/akStopWatch/trunk/SettingsForm.cs |
---|
0,0 → 1,18 |
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 SettingsForm : Form |
{ |
public SettingsForm() |
{ |
InitializeComponent(); |
} |
} |
} |
/akStopWatch/trunk/MainForm.Designer.cs |
---|
29,28 → 29,49 |
private void InitializeComponent() |
{ |
this.components=new System.ComponentModel.Container(); |
this.timer=new System.Windows.Forms.Timer(this.components); |
this.panel1=new System.Windows.Forms.Panel(); |
this.settingsButton=new System.Windows.Forms.Button(); |
this.timeLabel=new System.Windows.Forms.Label(); |
this.timer=new System.Windows.Forms.Timer(this.components); |
this.panel1.SuspendLayout(); |
this.SuspendLayout(); |
// |
// timer |
// |
this.timer.Interval=50; |
this.timer.Tick+=new System.EventHandler(this.timer_Tick); |
// |
// panel1 |
// |
this.panel1.Controls.Add(this.settingsButton); |
this.panel1.Location=new System.Drawing.Point(2, 2); |
this.panel1.Name="panel1"; |
this.panel1.Size=new System.Drawing.Size(289, 30); |
this.panel1.TabIndex=1; |
// |
// settingsButton |
// |
this.settingsButton.Location=new System.Drawing.Point(3, 4); |
this.settingsButton.Name="settingsButton"; |
this.settingsButton.Size=new System.Drawing.Size(75, 23); |
this.settingsButton.TabIndex=3; |
this.settingsButton.Text="Settings"; |
this.settingsButton.UseVisualStyleBackColor=true; |
this.settingsButton.Click+=new System.EventHandler(this.settingsButton_Click); |
// |
// timeLabel |
// |
this.timeLabel.Anchor=((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top|System.Windows.Forms.AnchorStyles.Bottom) |
|System.Windows.Forms.AnchorStyles.Left) |
|System.Windows.Forms.AnchorStyles.Right))); |
this.timeLabel.BackColor=System.Drawing.SystemColors.Control; |
this.timeLabel.Font=new System.Drawing.Font("Courier New", 72F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); |
this.timeLabel.Location=new System.Drawing.Point(0, 0); |
this.timeLabel.Location=new System.Drawing.Point(0, 35); |
this.timeLabel.Name="timeLabel"; |
this.timeLabel.Size=new System.Drawing.Size(293, 275); |
this.timeLabel.TabIndex=0; |
this.timeLabel.Size=new System.Drawing.Size(293, 239); |
this.timeLabel.TabIndex=2; |
this.timeLabel.Paint+=new System.Windows.Forms.PaintEventHandler(this.timeLabel_Paint); |
this.timeLabel.Click+=new System.EventHandler(this.MainForm_Click); |
// |
// timer |
// |
this.timer.Interval=1000; |
this.timer.Tick+=new System.EventHandler(this.timer_Tick); |
// |
// MainForm |
// |
this.AutoScaleDimensions=new System.Drawing.SizeF(6F, 13F); |
57,12 → 78,14 |
this.AutoScaleMode=System.Windows.Forms.AutoScaleMode.Font; |
this.ClientSize=new System.Drawing.Size(292, 273); |
this.Controls.Add(this.timeLabel); |
this.Controls.Add(this.panel1); |
this.KeyPreview=true; |
this.Name="MainForm"; |
this.Text="akStopWatch"; |
this.Load+=new System.EventHandler(this.MainForm_Load); |
this.FormClosed+=new System.Windows.Forms.FormClosedEventHandler(this.MainForm_FormClosed); |
this.KeyPress+=new System.Windows.Forms.KeyPressEventHandler(this.MainForm_KeyPress); |
this.Resize+=new System.EventHandler(this.MainForm_Resize); |
this.panel1.ResumeLayout(false); |
this.ResumeLayout(false); |
} |
69,8 → 92,10 |
#endregion |
private System.Windows.Forms.Timer timer; |
private System.Windows.Forms.Panel panel1; |
private System.Windows.Forms.Label timeLabel; |
private System.Windows.Forms.Timer timer; |
private System.Windows.Forms.Button settingsButton; |
} |
} |
/akStopWatch/trunk/MainForm.cs |
---|
10,42 → 10,106 |
{ |
public partial class MainForm : Form |
{ |
private int time = 0; |
public const string REGISTRY_KEY = @"Software\Anatoli Klassen\akStopWatch"; |
private int count = 3; |
public int Count { |
get { return count; } |
set { |
count = value; |
if(count < 1) count = 1; |
if(count > 10) count = 10; |
} |
} |
private TimeState[] times; |
public MainForm() |
{ |
InitializeComponent(); |
} |
private void MainForm_Click(object sender, EventArgs e) |
{ |
Start(); |
} |
private void LoadSettings() |
{ |
Microsoft.Win32.RegistryKey subkey = null; |
try |
{ |
subkey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(REGISTRY_KEY); |
if(subkey != null) |
{ |
Count = (int)subkey.GetValue("Count", Count); |
} |
} |
finally |
{ |
if(subkey != null) |
subkey.Close(); |
} |
} |
private void SaveSettings() |
{ |
Microsoft.Win32.RegistryKey subkey = null; |
try |
{ |
subkey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(REGISTRY_KEY); |
subkey.SetValue("Count", Count); |
} |
finally |
{ |
if(subkey != null) |
subkey.Close(); |
} |
} |
private void MainForm_KeyPress(object sender, KeyPressEventArgs e) |
{ |
Start(); |
int n = int.Parse(e.KeyChar.ToString()); |
if(n >= 0 && n < times.Length) |
{ |
times[n].Reset(DateTime.Now); |
ShowTime(); |
} |
} |
private void MainForm_Load(object sender, EventArgs e) |
{ |
Start(); |
LoadSettings(); |
Start(Count); |
} |
private void MainForm_Resize(object sender, EventArgs e) |
private void MainForm_FormClosed(object sender, FormClosedEventArgs e) |
{ |
SaveSettings(); |
} |
private void timer_Tick(object sender, EventArgs e) |
{ |
++time; |
ShowTime(); |
DateTime now = DateTime.Now; |
bool isChanged = false; |
foreach(TimeState t in times) |
{ |
isChanged |= t.IsChanged(now); |
} |
if(isChanged) { |
ShowTime(); |
} |
} |
private void Start() |
private void Start(int n) |
{ |
timer.Stop(); |
time = 0; |
times = new TimeState[n]; |
DateTime now = DateTime.Now; |
for(int i = 0; i < times.Length; ++i) |
{ |
times[i] = new TimeState(now); |
} |
ShowTime(); |
timer.Start(); |
} |
59,23 → 123,35 |
{ |
try |
{ |
Graphics g = e.Graphics; |
SolidBrush brush = new SolidBrush(Color.Black); |
Graphics g = e.Graphics; |
SolidBrush brushBig = new SolidBrush(Color.Black); |
SolidBrush brushSmall = new SolidBrush(Color.Red); |
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); |
float bigToSmall = 2.0f; |
string sampleBig = string.Format("{0:00}:{1:00}:{2:00}", 0, 0, 0); |
string sampleSmall = string.Format("{0:0}", 0); |
SizeF sizeBig = g.MeasureString(sampleBig, timeLabel.Font); |
SizeF sizeSmall = g.MeasureString(sampleSmall, timeLabel.Font); |
float k = Math.Min(timeLabel.Width / (sizeBig.Width + sizeSmall.Width / bigToSmall), |
timeLabel.Height / (sizeBig.Height * times.Length)); |
float dx = sizeSmall.Width * k / bigToSmall; |
float x = (timeLabel.Width - (sizeBig.Width + sizeSmall.Width / bigToSmall) * k) / 2; |
float dy = sizeBig.Height * k; |
float y = (timeLabel.Height - sizeBig.Height * times.Length * k) / 2; |
Font fontBig = new Font(timeLabel.Font.FontFamily, timeLabel.Font.Size * k, timeLabel.Font.Style); |
Font fontSmall = new Font(timeLabel.Font.FontFamily, timeLabel.Font.Size * k / bigToSmall, timeLabel.Font.Style); |
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); |
DateTime now = DateTime.Now; |
for(int i = 0; i < times.Length; ++i) |
{ |
TimeSpan time = times[i].GetDiff(now); |
string str = string.Format("{0:00}:{1:00}:{2:00}", time.Hours, time.Minutes, time.Seconds); |
g.DrawString(i.ToString(), fontSmall, brushSmall, x, y + dy * i); |
g.DrawString(str, fontBig, brushBig, x + dx, y + dy * i); |
} |
} |
catch(Exception ex) |
{ |
82,5 → 158,47 |
Console.WriteLine(ex.Message + "\n" + ex.StackTrace); |
} |
} |
private void settingsButton_Click(object sender, EventArgs e) |
{ |
SettingsForm f = new SettingsForm(); |
f.countBox.Value = times.Length; |
if(f.ShowDialog(this) == DialogResult.OK) |
{ |
Count = (int)f.countBox.Value; |
Start(Count); |
} |
} |
} |
class TimeState |
{ |
private DateTime begin; |
private DateTime last; |
public TimeState(DateTime now) |
{ |
Reset(now); |
} |
public void Reset(DateTime now) |
{ |
begin = now; |
last = DateTime.MinValue; |
} |
public bool IsChanged(DateTime now) |
{ |
TimeSpan diff = now.Subtract(last); |
return (diff.TotalSeconds > 0); |
} |
public TimeSpan GetDiff(DateTime now) |
{ |
last = now; |
return now.Subtract(begin); |
} |
} |
} |
/akStopWatch/trunk/Properties/AssemblyInfo.cs |
---|
6,7 → 6,7 |
// set of attributes. Change these attribute values to modify the information |
// associated with an assembly. |
[assembly: AssemblyTitle("akStopWatch")] |
[assembly: AssemblyDescription("A simplest stop-watch - restarts on click on key press")] |
[assembly: AssemblyDescription("A simplest stop-watch - multiple counters controlled by single key press")] |
[assembly: AssemblyConfiguration("")] |
[assembly: AssemblyCompany("Anatoli Klassen")] |
[assembly: AssemblyProduct("akStopWatch")] |