下面是程序全部代码;
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
this.Form.Control.Add(label1);
Graphics g;
int x, y, x1, y1;//计算表盘时用
int xs, ys, xm, ym, xh, yh;//分别代表秒针分针时针位置
int xsl, ysl, xml, yml, xhl, yhl;//记录上一状态
int r = 40; // 半径
Point p;
//= new Point(100, 100);// 圆心位置
Pen penSecond, penSecondLast, penMinute, penMinuteLast, penHour, penHourLast;
Color colorBackground = Color.White;
bool click;
int mouse_x;
int mouse_y;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
g = this.CreateGraphics();
this.TopMost = true;
label1.Text = DateTime.Now.ToString();
p = new Point(this.Width / 2, this.Height / 2 + 2);
int second = DateTime.Now.Second;
int minute = DateTime.Now.Minute;
int hour = DateTime.Now.Hour % 12;
//秒针
ys = 0 - (int)(Math.Sin((90 - second * 6) * Math.PI / 180) * r * 0.9) + p.Y;
xs = (int)(Math.Cos((90 - second * 6) * Math.PI / 180) * r * 0.95) + p.X;
//分针
ym = 0 - (int)(Math.Sin((90 - minute * 6 - second / 10) * Math.PI / 180) * r * 0.8) + p.Y;
xm = (int)(Math.Cos((90 - minute * 6 - second / 10) * Math.PI / 180) * r * 0.8) + p.X;
//时针
yh = 0 - (int)(Math.Sin((90 - hour * 30 - minute / 2 - second / 120) * Math.PI / 180) * r * 0.6) + p.Y;
xh = (int)(Math.Cos((90 - hour * 30 - minute / 2 - second / 120) * Math.PI / 180) * r * 0.6) + p.X;
//秒针
penSecond = new Pen(Color.Red, 2);
penSecond.EndCap = LineCap.RoundAnchor;
penSecondLast = new Pen(colorBackground, 2);
penSecondLast.EndCap = LineCap.RoundAnchor;
//分针
penMinute = new Pen(Color.BlueViolet, 4);
penMinute.EndCap = LineCap.Round;
penMinuteLast = new Pen(colorBackground, 4);
penMinuteLast.EndCap = LineCap.Round;
//时针
penHour = new Pen(Color.Black, 6);
penHour.EndCap = LineCap.Round;
penHourLast = new Pen(colorBackground, 6);
penHourLast.EndCap = LineCap.Round;
//this.ShowInTaskbar = false;
#region 最小化图标
notifyIcon1.ShowBalloonTip(5000, "提示", "小可钟表运行", ToolTipIcon.Info);
MenuItem menuItem1 = new MenuItem("调整");
MenuItem menuItem2 = new MenuItem("退出");
menuItem1.Click+=new EventHandler(menuItem1_Click);
menuItem2.Click += new EventHandler(menuItem2_Click);
notifyIcon1.ContextMenu = new ContextMenu(new MenuItem[] { menuItem1, menuItem2 });
#endregion
}
private void timer1_Tick(object sender, EventArgs e)
{
int second = DateTime.Now.Second;
int minute = DateTime.Now.Minute;
int hour = DateTime.Now.Hour % 12;
//时针
xhl = xh;
yhl = yh;
yh = 0 - (int)(Math.Sin((90 - hour * 30 - minute / 2 - second / 120) * Math.PI / 180) * r * 0.6) + p.Y;
xh = (int)(Math.Cos((90 - hour * 30 - minute / 2 - second / 120) * Math.PI / 180) * r * 0.6) + p.X;
//分针
xml = xm;
yml = ym;
ym = 0 - (int)(Math.Sin((90 - minute * 6 - second / 10) * Math.PI / 180) * r * 0.78) + p.Y;
xm = (int)(Math.Cos((90 - minute * 6 - second / 10) * Math.PI / 180) * r * 0.78) + p.X;
//秒针
xsl = xs;
ysl = ys;
ys = 0 - (int)(Math.Sin((90 - second * 6) * Math.PI / 180) * r * 0.82) + p.Y;
xs = (int)(Math.Cos((90 - second * 6) * Math.PI / 180) * r * 0.82) + p.X;
g.DrawLine(penHourLast, p, new Point(xhl, yhl));
g.DrawLine(penMinuteLast, p, new Point(xml, yml));
g.DrawLine(penSecondLast, p, new Point(xsl, ysl));
label1.Text = DateTime.Now.ToString();
g.DrawLine(penHour, p, new Point(xh, yh));
g.DrawLine(penMinute, p, new Point(xm, ym));
g.DrawLine(penSecond, p, new Point(xs, ys));
}
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Left)
return;
mouse_x = e.X;
mouse_y = e.Y;
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
this.Left += e.X - mouse_x;
this.Top += e.Y - mouse_y;
}
//右击图标的"退出"
void menuItem2_Click(object sender, EventArgs e)
{
this.Dispose();
Environment.Exit(0);
}
void menuItem1_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("timedate.cpl");
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
Environment.Exit(0);
}
}
}
8 个解决方案
#1
一共有三个错误,Error 1 Invalid token 'this' in class, struct, or interface member declaration C:\Users\Ervel\Documents\Visual Studio 2008\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 14 9 WindowsFormsApplication1
Error 2 Invalid token '(' in class, struct, or interface member declaration C:\Users\Ervel\Documents\Visual Studio 2008\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 14 30 WindowsFormsApplication1
Error 3 Invalid token ')' in class, struct, or interface member declaration C:\Users\Ervel\Documents\Visual Studio 2008\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 14 37 WindowsFormsApplication1
Error 2 Invalid token '(' in class, struct, or interface member declaration C:\Users\Ervel\Documents\Visual Studio 2008\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 14 30 WindowsFormsApplication1
Error 3 Invalid token ')' in class, struct, or interface member declaration C:\Users\Ervel\Documents\Visual Studio 2008\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 14 37 WindowsFormsApplication1
#2
麻烦那位大侠帮忙解决,谢谢
#3
this.Control.Add(label1);?
#4
嗯。就是这行
#5
开始是Error 1 The name 'label1' does not exist in the current context C:\Users\Ervel\Documents\Visual Studio 2008\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 40 13 WindowsFormsApplication1这个,有10多个,全部是这类错误,我后来查询了下,要加一个
this.Control.Add(label1);加了后,就出现了现在存在的问题。太纠结了
this.Control.Add(label1);加了后,就出现了现在存在的问题。太纠结了
#6
在form_load中添加Control.Add(label1);
#7
嗯。直接出现这样的错误
'System.Windows.Forms.Control'does not contain a definition for 'Add'
还有The name 'label1'does not exist in the current context
'System.Windows.Forms.Control'does not contain a definition for 'Add'
还有The name 'label1'does not exist in the current context
#8
Error 1 'System.Windows.Forms.Control' does not contain a definition for 'Add' C:\Users\Ervel\Documents\Visual Studio 2008\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 37 21 WindowsFormsApplication1
Error 2 The name 'label1' does not exist in the current context C:\Users\Ervel\Documents\Visual Studio 2008\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 37 25 WindowsFormsApplication1
Error 3 The name 'label1' does not exist in the current context C:\Users\Ervel\Documents\Visual Studio 2008\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 40 13 WindowsFormsApplication1
.
.
.
.
.
.
.
Error 2 The name 'label1' does not exist in the current context C:\Users\Ervel\Documents\Visual Studio 2008\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 37 25 WindowsFormsApplication1
Error 3 The name 'label1' does not exist in the current context C:\Users\Ervel\Documents\Visual Studio 2008\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 40 13 WindowsFormsApplication1
.
.
.
.
.
.
.
#1
一共有三个错误,Error 1 Invalid token 'this' in class, struct, or interface member declaration C:\Users\Ervel\Documents\Visual Studio 2008\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 14 9 WindowsFormsApplication1
Error 2 Invalid token '(' in class, struct, or interface member declaration C:\Users\Ervel\Documents\Visual Studio 2008\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 14 30 WindowsFormsApplication1
Error 3 Invalid token ')' in class, struct, or interface member declaration C:\Users\Ervel\Documents\Visual Studio 2008\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 14 37 WindowsFormsApplication1
Error 2 Invalid token '(' in class, struct, or interface member declaration C:\Users\Ervel\Documents\Visual Studio 2008\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 14 30 WindowsFormsApplication1
Error 3 Invalid token ')' in class, struct, or interface member declaration C:\Users\Ervel\Documents\Visual Studio 2008\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 14 37 WindowsFormsApplication1
#2
麻烦那位大侠帮忙解决,谢谢
#3
this.Control.Add(label1);?
#4
嗯。就是这行
#5
开始是Error 1 The name 'label1' does not exist in the current context C:\Users\Ervel\Documents\Visual Studio 2008\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 40 13 WindowsFormsApplication1这个,有10多个,全部是这类错误,我后来查询了下,要加一个
this.Control.Add(label1);加了后,就出现了现在存在的问题。太纠结了
this.Control.Add(label1);加了后,就出现了现在存在的问题。太纠结了
#6
在form_load中添加Control.Add(label1);
#7
嗯。直接出现这样的错误
'System.Windows.Forms.Control'does not contain a definition for 'Add'
还有The name 'label1'does not exist in the current context
'System.Windows.Forms.Control'does not contain a definition for 'Add'
还有The name 'label1'does not exist in the current context
#8
Error 1 'System.Windows.Forms.Control' does not contain a definition for 'Add' C:\Users\Ervel\Documents\Visual Studio 2008\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 37 21 WindowsFormsApplication1
Error 2 The name 'label1' does not exist in the current context C:\Users\Ervel\Documents\Visual Studio 2008\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 37 25 WindowsFormsApplication1
Error 3 The name 'label1' does not exist in the current context C:\Users\Ervel\Documents\Visual Studio 2008\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 40 13 WindowsFormsApplication1
.
.
.
.
.
.
.
Error 2 The name 'label1' does not exist in the current context C:\Users\Ervel\Documents\Visual Studio 2008\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 37 25 WindowsFormsApplication1
Error 3 The name 'label1' does not exist in the current context C:\Users\Ervel\Documents\Visual Studio 2008\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 40 13 WindowsFormsApplication1
.
.
.
.
.
.
.