7,655
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using TransparentControl;
namespace NFStopWatch2
{
public partial class headshow : TransPanel
{
private TransLabel h_lbl, m_lbl, s_lbl, mi_lbl;
public headshow(int alpha,Bitmap headbj,Bitmap lblbj)
{
this.Alpha = alpha;
this.BackGroundImage = headbj;
InitializeComponent();
int left=15;
h_lbl = new TransLabel();
h_lbl.Width = 115;
h_lbl.Left = left;
h_lbl.Top = 20;
this.Controls.Add(h_lbl);
TransLabel t1_lbl = new TransLabel();
t1_lbl.Width = 15;
t1_lbl.Left = left + h_lbl.Width;
t1_lbl.Top = 15;
t1_lbl.Text = ":";
this.Controls.Add(t1_lbl);
m_lbl = new TransLabel();
m_lbl.Width = 80;
m_lbl.Left = left + h_lbl.Width + t1_lbl.Width;
m_lbl.Top = 20;
this.Controls.Add(m_lbl);
TransLabel t2_lbl = new TransLabel();
t2_lbl.Width = 15;
t2_lbl.Left = left + h_lbl.Width + t1_lbl.Width + m_lbl.Width;
t2_lbl.Top = 15;
t2_lbl.Text = ":";
this.Controls.Add(t2_lbl);
s_lbl = new TransLabel();
s_lbl.Width = 80;
s_lbl.Left = left + h_lbl.Width + t1_lbl.Width + m_lbl.Width + t2_lbl.Width;
s_lbl.Top = 20;
this.Controls.Add(s_lbl);
TransLabel t3_lbl = new TransLabel();
t3_lbl.Width = 15;
t3_lbl.Left = left + h_lbl.Width + t1_lbl.Width + m_lbl.Width + t2_lbl.Width + s_lbl.Width;
t3_lbl.Top = 15;
t3_lbl.Text = ".";
this.Controls.Add(t3_lbl);
mi_lbl = new TransLabel();
mi_lbl.Width = 80;
mi_lbl.Left = left + h_lbl.Width + t1_lbl.Width + m_lbl.Width + t2_lbl.Width + s_lbl.Width + t3_lbl.Width + 3;
mi_lbl.Height = 50;
mi_lbl.Font = new Font("Tahoma", 16, FontStyle.Regular);
mi_lbl.ForeColor = Color.White;
mi_lbl.TextAlign = ContentAlignment.TopCenter;
mi_lbl.Top = 40;
this.Controls.Add(mi_lbl);
foreach (Control ctl in this.Controls)
{
TransLabel tlbl = ctl as TransLabel;
if (tlbl != null && tlbl!=mi_lbl)
{
tlbl.Height = 80;
tlbl.Font = new Font("Tahoma", 25, FontStyle.Regular);
tlbl.ForeColor = Color.White;
tlbl.TextAlign = ContentAlignment.TopCenter;
tlbl.Alpha = alpha;
tlbl.BackGroundImage = lblbj;
}
}
TimeInit();
}
public void TimeInit()
{
h_lbl.Text = "000";
m_lbl.Text = "00";
s_lbl.Text = "00";
mi_lbl.Text = "000";
}
public void SetTime(TimeSpan ts)
{
int hnum = ts.Days * 24 + ts.Hours;
mi_lbl.Text = ts.Milliseconds.ToString("000");
s_lbl.Text = ts.Seconds.ToString("00");
m_lbl.Text = ts.Minutes.ToString("00");
h_lbl.Text = hnum.ToString("000");
}
protected override void OnPaint(PaintEventArgs pe)
{
// TODO: 在此处添加自定义绘制代码
// Calling the base class OnPaint
base.OnPaint(pe);
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using TransparentControl;
namespace NFStopWatch2
{
public partial class listshow_tc : TransLabel
{
TransPanel tp;
public listshow_tc()
{
InitializeComponent();
}
protected override void OnMouseDown(MouseEventArgs e)
{
tp = this.Parent as TransPanel;
if (tp != null)
{
MouseEventArgs me = new MouseEventArgs(e.Button, 1, e.X + this.Left, e.Y + this.Top, 0);
tp.OnMouseDown_p(me);
}
//base.OnMouseDown(e);
}
protected override void OnMouseUp(MouseEventArgs e)
{
tp = this.Parent as TransPanel;
if (tp != null)
{
MouseEventArgs me = new MouseEventArgs(e.Button, 1, e.X + this.Left, e.Y + this.Top, 0);
tp.OnMouseUp_p(me);
}
//base.OnMouseUp(e);
}
protected override void OnMouseMove(MouseEventArgs e)
{
tp = this.Parent as TransPanel;
if (tp != null)
{
MouseEventArgs me = new MouseEventArgs(e.Button, 1, e.X + this.Left, e.Y + this.Top, 0);
tp.OnMouseMove_p(me);
}
//base.OnMouseMove(e);
}
protected override void OnClick(EventArgs e)
{
tp = this.Parent as TransPanel;
if (tp != null)
{
tp.OnClick_p(e);
}
//base.OnClick(e);
}
protected override void OnPaint(PaintEventArgs pe)
{
// TODO: 在此处添加自定义绘制代码
// Calling the base class OnPaint
base.OnPaint(pe);
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using TransparentControl;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace NFStopWatch2
{
public partial class StopWatch : TransForm
{
private int tnum = 0;
private int jsnum = 0;
private string typestr = "c";
private int ph = 48;
private headshow headshow1;
private listshow_tc listshow;
// private TransControl tstop_btn;
Stopwatch sw = new Stopwatch();
TimeSpan last_ts = TimeSpan.FromMilliseconds(0);
private Bitmap bm_zzbj;
private Bitmap bm_toolbj;
private Bitmap bm_sjshowbj1;
private Bitmap bm_sjshowbj2;
private Bitmap bm_showbj;
private Bitmap bm_jsbtn1;
private Bitmap bm_jsbtn2;
private Bitmap bm_typebtn1;
private Bitmap bm_typebtn2;
[DllImport("CoreDll.dll")]
private static extern void SystemIdleTimerReset();
public StopWatch()
{
bm_zzbj = new Bitmap(this.SysPath + "\\Resources\\zzbj.jpg");
bm_toolbj = new Bitmap(NFStopWatch2.Properties.Resources.toolbj);
bm_sjshowbj1 = new Bitmap(NFStopWatch2.Properties.Resources.sjshowbj1);
bm_sjshowbj2 = new Bitmap(NFStopWatch2.Properties.Resources.sjshowbj2);
bm_showbj = new Bitmap(NFStopWatch2.Properties.Resources.showbj);
bm_jsbtn1 = new Bitmap(NFStopWatch2.Properties.Resources.jsbtn1);
bm_jsbtn2 = new Bitmap(NFStopWatch2.Properties.Resources.jsbtn2);
bm_typebtn1 = new Bitmap(NFStopWatch2.Properties.Resources.typebtn1);
bm_typebtn2 = new Bitmap(NFStopWatch2.Properties.Resources.typebtn2);
this.BackGroundImage = bm_zzbj;
InitializeComponent();
toolpanel.Alpha = 255;
toolpanel.BackGroundImage = bm_toolbj;
headshow1 = new NFStopWatch2.headshow(60, bm_sjshowbj1, bm_sjshowbj2);
headshow1.Location = new System.Drawing.Point(24, 22);
headshow1.Size = new System.Drawing.Size(430, 115);
transPanel1.Controls.Add(headshow1);
tstop_btn.Image = bm_jsbtn1;
type_btn.Image = bm_typebtn2;
//tstop_btn = new TransControl();
//tstop_btn.Width = 151;
//tstop_btn.Height = 79;
//tstop_btn.Left = 310;
//tstop_btn.Top = 12;
//tstop_btn.BackGroundImage = bm_jsbtn;
//toolpanel.Controls.Add(tstop_btn);
//tstop_btn.Click += new EventHandler(tstop_btn_Click);
init();
}
private void init()
{
sw.Reset();
heartimer.Enabled = false;
listpanel.Controls.Clear();
last_ts = TimeSpan.FromMilliseconds(0);
tnum = 0;
jsnum = 0;
type_btn.Enabled = true;
tstop_btn.Enabled = false;
start_mi.Enabled = true;
start_mi.Text = "开始";
headshow1.TimeInit();
}
private void start()
{
if (!sw.IsRunning)
{
sw.Start();
heartimer.Enabled = true;
type_btn.Enabled = false;
tstop_btn.Enabled = true;
start_mi.Text = "停止";
listpanel.ScrollEnable = false;
}
}
private void stop()
{
if (sw.IsRunning)
{
sw.Stop();
heartimer.Enabled = false;
tstop_btn.Enabled = false;
start_mi.Enabled = false;
listpanel.ScrollEnable = true;
}
}
private void t_js()
{
TimeSpan tts = TimeSpan.FromMilliseconds(sw.ElapsedMilliseconds);
TimeSpan ts = tts;
if (typestr == "q" && last_ts.Milliseconds > 0)
{
ts = tts - last_ts;
}
foreach (Control ctl in listpanel.Controls)
{
TransLabel tl = ctl as TransLabel;
if (tl != null)
tl.Top = tl.Top + ph + 4;
}
listshow = new listshow_tc();
listshow.Parent = listpanel;
listshow.Width = listpanel.Width - 55;
listshow.Height = ph;
listshow.Top = 0;// ph * tnum + 4 * tnum;
listshow.Left = 26;
listshow.ForeColor = Color.White;
listshow.Font = new Font("Tahoma", 13, FontStyle.Regular);
listshow.Text = String.Format(" {0} {1}:{2:00}:{3:00}.{4:000}", (tnum + 1).ToString().PadLeft(3, ' '), (ts.Days * 24 + ts.Hours).ToString().PadLeft(3, ' '), ts.Minutes, ts.Seconds, ts.Milliseconds);
listshow.Alpha = 60;
listshow.BackGroundImage = bm_showbj;
listpanel.Controls.Add(listshow);
last_ts = tts;
tnum++;
}
private void heartimer_Tick(object sender, EventArgs e)
{
if (sw.IsRunning)
{
TimeSpan ts = TimeSpan.FromMilliseconds(sw.ElapsedMilliseconds);
int hnum = ts.Days * 24 + ts.Hours;
if (hnum > 999)
{
stop();
MessageBox.Show("超过最大时长");
return;
}
else
{
headshow1.SetTime(ts);
}
jsnum++;
if (jsnum >= 15000)
{
SystemIdleTimerReset();
jsnum = 0;
}
}
}
private void reset_mi_Click(object sender, EventArgs e)
{
init();
}
private void start_mi_Click(object sender, EventArgs e)
{
if (sw.IsRunning)
{
stop();
t_js();
}
else
{
start();
}
}
private void tstop_btn_Click(object sender, EventArgs e)
{
t_js();
}
private void tstop_btn_MouseDown(object sender, MouseEventArgs e)
{
tstop_btn.Image = bm_jsbtn2;
}
private void tstop_btn_MouseUp(object sender, MouseEventArgs e)
{
tstop_btn.Image = bm_jsbtn1;
}
private void type_btn_Click(object sender, EventArgs e)
{
if (typestr == "c")
{
typestr = "q";
type_btn.Image = bm_typebtn1;
}
else
{
typestr = "c";
type_btn.Image = bm_typebtn2;
}
} }
}