code=C#] private void DrawTimer(Graphics g)
{
//画时钟外表
for (double k = 0; k <= 360; k += 6)
{
d = (double)(k * Math.PI / 180);
float x1 = (float)(160 * Math.Sin(d) + 200);
float y1 = (float)(200 - 160 * Math.Cos(d));
if (k % 30 == 0)
{
g.FillEllipse(new SolidBrush(Color.Green), x1 - 5, y1 - 5, 10, 10);
}
else
{
g.FillEllipse(new SolidBrush(Color.Red), x1 - 5, y1 - 5, 5, 5);
}
}
while (true)
{
degree = (double)(s * Math.PI / 30);
if (true)
{
//秒针
float x = (float)(150 * Math.Sin(degree) + 200);
float y = (float)(200 - 150 * Math.Cos(degree));
g.DrawLine(new Pen(Color.Blue), new Point(200, 200), new PointF(x, y)); //分针
mX = (float)(130 * Math.Sin(mdegree) + 200);
mY = (float)(200 - 130 * Math.Cos(mdegree));
g.DrawLine(new Pen(Color.Red, 2), new Point(200, 200), new PointF(mX, mY));
mdegree += (float)(1 * Math.PI / 1800); //画时针
hX = (float)(120 * Math.Sin(hdegree) + 200);
hY = (float)(200 - 120 * Math.Cos(hdegree));
g.DrawLine(new Pen(Color.Gold, 3), new Point(200, 200), new PointF(hX, hY));
hdegree += (float)(1 * Math.PI / 21600); System.Threading.Thread.Sleep(1000);
g.DrawLine(new Pen(myForm.BackColor), new Point(200, 200), new PointF(x, y));
g.DrawLine(new Pen(myForm.BackColor, 2), new Point(200, 200), new PointF(mX, mY));
g.DrawLine(new Pen(myForm.BackColor, 3), new Point(200, 200), new PointF(hX, hY));
}
s = Convert.ToInt32(DateTime.Now.Second.ToString());
}
}[[/code]
该方法在Timer类中实现
在主程序用
Graphics g = e.Graphics;
Timer myTimer = new Timer();
ThreadPool.QueueUserWorkItem(new WaitCallback(myTimer.DrawTimer),g);
调用
但出现如下错误
g.FillEllipse(new SolidBrush(Color.Green), x1 - 5, y1 - 5, 10, 10);
参数无效
高手帮解答
{
//画时钟外表
for (double k = 0; k <= 360; k += 6)
{
d = (double)(k * Math.PI / 180);
float x1 = (float)(160 * Math.Sin(d) + 200);
float y1 = (float)(200 - 160 * Math.Cos(d));
if (k % 30 == 0)
{
g.FillEllipse(new SolidBrush(Color.Green), x1 - 5, y1 - 5, 10, 10);
}
else
{
g.FillEllipse(new SolidBrush(Color.Red), x1 - 5, y1 - 5, 5, 5);
}
}
while (true)
{
degree = (double)(s * Math.PI / 30);
if (true)
{
//秒针
float x = (float)(150 * Math.Sin(degree) + 200);
float y = (float)(200 - 150 * Math.Cos(degree));
g.DrawLine(new Pen(Color.Blue), new Point(200, 200), new PointF(x, y)); //分针
mX = (float)(130 * Math.Sin(mdegree) + 200);
mY = (float)(200 - 130 * Math.Cos(mdegree));
g.DrawLine(new Pen(Color.Red, 2), new Point(200, 200), new PointF(mX, mY));
mdegree += (float)(1 * Math.PI / 1800); //画时针
hX = (float)(120 * Math.Sin(hdegree) + 200);
hY = (float)(200 - 120 * Math.Cos(hdegree));
g.DrawLine(new Pen(Color.Gold, 3), new Point(200, 200), new PointF(hX, hY));
hdegree += (float)(1 * Math.PI / 21600); System.Threading.Thread.Sleep(1000);
g.DrawLine(new Pen(myForm.BackColor), new Point(200, 200), new PointF(x, y));
g.DrawLine(new Pen(myForm.BackColor, 2), new Point(200, 200), new PointF(mX, mY));
g.DrawLine(new Pen(myForm.BackColor, 3), new Point(200, 200), new PointF(hX, hY));
}
s = Convert.ToInt32(DateTime.Now.Second.ToString());
}
}[[/code]
该方法在Timer类中实现
在主程序用
Graphics g = e.Graphics;
Timer myTimer = new Timer();
ThreadPool.QueueUserWorkItem(new WaitCallback(myTimer.DrawTimer),g);
调用
但出现如下错误
g.FillEllipse(new SolidBrush(Color.Green), x1 - 5, y1 - 5, 10, 10);
参数无效
高手帮解答
解决方案 »
- 求获取本地某个文件夹中所有的文件名和数量的详细代码!!
- 向数据库中插入 numeric 字段问题
- 如何在系统的窗体上添加自己的窗体
- 求控件 Developer Express --> XtraGrid 网格中文用法?
- C#里怎么实现 CreateObject
- 怎样将image类型的数据转换为byte[]类型
- while ((input = sr.ReadLine()) != null){XXX}读txt,会卡死,求助
- 各位帮帮忙,CheckedListBox的Checked问题。
- 怎么就是关不掉
- 高手请指教,在DataTable中如何对数据进行排序(按3个字段)
- HTML代码里如何删除整块控件?
- (WFC)为什么运行svcutil.exe http://xxxxxx.com/Services.svc?wsdl不可以创建出配置文件?
带参数的方法
用这个
Timer myTimer = new Timer();
ThreadPool.QueueUserWorkItem(new WaitCallback(myTimer.DrawTimer),g);
可以解决吧
您是传了个引用进去吧