level 7
痴迷的程序员
楼主
//xmal页面代码
<Canvas>
<Ellipse Stroke="Transparent" Width="120" Height="120">
<Ellipse.Fill>
<RadialGradientBrush>
<GradientStop Color="White" Offset="0"></GradientStop>
<GradientStop Color="#DBDDE6" Offset="0.7"></GradientStop>
<GradientStop Color="#ACABC4" Offset="1"></GradientStop>
</RadialGradientBrush>
</Ellipse.Fill>
</Ellipse>
<Line Name="lnHor" Stroke="Red" StrokeThickness="3" X1="60" Y1="60" X2="60" Y2="60"></Line>
<Line Name="lnMin" Stroke="Yellow" StrokeThickness="2" X1="60" Y1="60" X2="60" Y2="60"></Line>
<Line Name="lnSec" Stroke="Blue" StrokeThickness="2" X1="60" Y1="60" X2="60" Y2="60"></Line>
<Ellipse Stroke="White" Width="7" Height="7" Fill="Black" Canvas.Left="57" Canvas.Top="57">
</Ellipse>
<sdk:Label Name="lbl" Width="100" Height="20" Canvas.Left="100" Canvas.Top="120"/>
</Canvas>
//后端代码
//定义属性
DispatcherTimer timer;
const int secLen = 50;
const int minLen = 43;
const int horLen = 35;
DateTime dt;
int sec;
int min;
int hor;
double angle;
public MainPage()
{
InitializeComponent();
lbl.Content = "简单时钟制作";
timer = new DispatcherTimer();
timer.Interval = new TimeSpan(0, 0, 1);
timer.Start();
timer.Tick += new EventHandler(timer_Tick);
}
//获取时钟的方法
void timer_Tick(object sender,EventArgs e)
{
//获取当前时间
dt = DateTime.Now;
sec = dt.Second;//获取秒
min = dt.Minute;//获取分钟
hor = dt.Hour;//获取小时
angle = Math.PI / 30 * sec - Math.PI / 2;
lnSec.X2 = 60 + Math.Cos(angle) * secLen;
lnSec.Y2 = 60 + Math.Sin(angle) * secLen;
angle = Math.PI / 1800 * (min * 60 + sec) - Math.PI / 2;
lnMin.X2 = 60 + Math.Cos(angle) * minLen;
lnMin.Y2 = 60 + Math.Sin(angle) * minLen;
angle = Math.PI / 21600 * (hor * 3600 + min * 60 + sec) - Math.PI / 2;
lnHor.X2 = 60 + Math.Cos(angle) * horLen;
lnHor.Y2 = 60 + Math.Sin(angle) * horLen;
}
2016年09月06日 02点09分
1
<Canvas>
<Ellipse Stroke="Transparent" Width="120" Height="120">
<Ellipse.Fill>
<RadialGradientBrush>
<GradientStop Color="White" Offset="0"></GradientStop>
<GradientStop Color="#DBDDE6" Offset="0.7"></GradientStop>
<GradientStop Color="#ACABC4" Offset="1"></GradientStop>
</RadialGradientBrush>
</Ellipse.Fill>
</Ellipse>
<Line Name="lnHor" Stroke="Red" StrokeThickness="3" X1="60" Y1="60" X2="60" Y2="60"></Line>
<Line Name="lnMin" Stroke="Yellow" StrokeThickness="2" X1="60" Y1="60" X2="60" Y2="60"></Line>
<Line Name="lnSec" Stroke="Blue" StrokeThickness="2" X1="60" Y1="60" X2="60" Y2="60"></Line>
<Ellipse Stroke="White" Width="7" Height="7" Fill="Black" Canvas.Left="57" Canvas.Top="57">
</Ellipse>
<sdk:Label Name="lbl" Width="100" Height="20" Canvas.Left="100" Canvas.Top="120"/>
</Canvas>
//后端代码
//定义属性
DispatcherTimer timer;
const int secLen = 50;
const int minLen = 43;
const int horLen = 35;
DateTime dt;
int sec;
int min;
int hor;
double angle;
public MainPage()
{
InitializeComponent();
lbl.Content = "简单时钟制作";
timer = new DispatcherTimer();
timer.Interval = new TimeSpan(0, 0, 1);
timer.Start();
timer.Tick += new EventHandler(timer_Tick);
}
//获取时钟的方法
void timer_Tick(object sender,EventArgs e)
{
//获取当前时间
dt = DateTime.Now;
sec = dt.Second;//获取秒
min = dt.Minute;//获取分钟
hor = dt.Hour;//获取小时
angle = Math.PI / 30 * sec - Math.PI / 2;
lnSec.X2 = 60 + Math.Cos(angle) * secLen;
lnSec.Y2 = 60 + Math.Sin(angle) * secLen;
angle = Math.PI / 1800 * (min * 60 + sec) - Math.PI / 2;
lnMin.X2 = 60 + Math.Cos(angle) * minLen;
lnMin.Y2 = 60 + Math.Sin(angle) * minLen;
angle = Math.PI / 21600 * (hor * 3600 + min * 60 + sec) - Math.PI / 2;
lnHor.X2 = 60 + Math.Cos(angle) * horLen;
lnHor.Y2 = 60 + Math.Sin(angle) * horLen;
}