热门:网页模板.net视频教程JQueryMVCjsonExtJs源码示例三级联动JQuery菜单
您现在的位置:.Net中文社区>> Silverlight>>正文内容

Silverlight 制作电子表

发布时间:2009年12月28日点击数: 未知

效果图如下:

程序是用VS2010 beta 写的, 使用的是 VS2010 默认创建的 Silverlight 项目来编写的。
MainPage.xaml 文件

  1. <UserControl x:Class="ClockSilverlightApp.MainPage" 
  2.     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  3.     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
  4.     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
  5.     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
  6.     mc:Ignorable="d" 
  7.     d:DesignHeight="300" d:DesignWidth="400" Loaded="UserControl_Loaded"> 
  8.  
  9.     <Canvas 
  10.     xmlns="http://schemas.microsoft.com/client/2007" 
  11.     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
  12.     Width="180" Height="150" 
  13.     Background="#0030628D" 
  14.     x:Name="Page" > 
  15.         <Rectangle x:Name="Frame" Width="180" Height="150" Stroke="#FF000000" StrokeThickness="1" RadiusX="20" RadiusY="15"> 
  16.             <Rectangle.Fill> 
  17.                 <LinearGradientBrush EndPoint="0.5,1.1" StartPoint="0.5,-0.1"> 
  18.                     <GradientStop Color="#FF259888" Offset="0"/> 
  19.                     <GradientStop Color="#FF259888" Offset="0.981"/> 
  20.                     <GradientStop Color="#FFC87947" Offset="0.416"/> 
  21.                     <GradientStop Color="#FFC87947" Offset="0.636"/> 
  22.                 LinearGradientBrush> 
  23.             Rectangle.Fill> 
  24.         Rectangle> 
  25.         <Rectangle x:Name="Panel" Width="164" Height="134" Fill="#7F91B52C" Stroke="#FFA2AEBF" RadiusX="50" RadiusY="15" Canvas.Left="8" Canvas.Top="8" StrokeThickness="2"/> 
  26.  
  27.         <Path x:Name="Line1" Width="163" Height="1" Fill="#FF100888" Stretch="Fill" Stroke="#FF1B510C" Canvas.Left="8" Canvas.Top="92" Data="M33.50029,83.29705 L161.89657,83.297051"/> 
  28.         <Path x:Name="Line2" Width="1" Height="49" Fill="#FF100888" Stretch="Fill" Stroke="#FF1B510C" Canvas.Left="56" Canvas.Top="92" Data="M81.450752,138.29705 L81.450752,90.29705"/> 
  29.         <Path x:Name="Line3" Width="1" Height="49" Fill="#FF100888" Stretch="Fill" Stroke="#FF1B510C" Canvas.Left="110" Canvas.Top="92" Data="M118.30501,164.29698 L118.30501,116.29699"/> 
  30.  
  31.         <TextBlock x:Name="Month" Width="16" Height="19" Canvas.Left="30" Canvas.Top="92" TextWrapping="Wrap" Foreground="#FF100888" Text="月"/> 
  32.         <TextBlock Width="16" Height="19" Canvas.Left="78" Canvas.Top="92" TextWrapping="Wrap" x:Name="Day" Foreground="#FF100888" Text="日"/> 
  33.         <TextBlock Width="30" Height="19" Canvas.Left="129" Canvas.Top="92" TextWrapping="Wrap" x:Name="Week" Foreground="#FF100888" Text="星期"/> 
  34.  
  35.         <TextBlock x:Name="txtMonth" Width="19" Height="19" Canvas.Left="28" Canvas.Top="111" TextWrapping="Wrap" Foreground="#FF100888" Text="12"/> 
  36.         <TextBlock x:Name="txtDay" Width="20.5" Height="19" Canvas.Left="77" Canvas.Top="111" TextWrapping="Wrap" Foreground="#FF100888" Text="31"/> 
  37.         <TextBlock x:Name="txtWeek" Width="20" Height="19" Canvas.Left="133" Canvas.Top="111" TextWrapping="Wrap" Foreground="#FF100888" Text="六"/> 
  38.  
  39.         <TextBlock x:Name="txtHour" Width="48" Height="48" Canvas.Left="14.5" Canvas.Top="38" TextWrapping="Wrap" FontSize="36" Foreground="#FF100888" Text="23"/> 
  40.         <TextBlock x:Name="txtMinute" Width="48" Height="48" Canvas.Left="68.5" Canvas.Top="38" TextWrapping="Wrap" FontSize="36" Foreground="#FF100888" Text="59"/> 
  41.         <TextBlock x:Name="txtSecond" Width="49" Height="48" Canvas.Left="122" Canvas.Top="38" TextWrapping="Wrap" FontSize="36" Foreground="#FF100888" Text="59"/> 
  42.  
  43.         <TextBlock x:Name="Colon1" Width="9.5" Height="27" Canvas.Left="62.5" Canvas.Top="48" TextWrapping="Wrap" Foreground="#FF100888" Text=":" FontSize="20"/> 
  44.         <TextBlock x:Name="Colon2" Width="12" Height="27" Canvas.Left="116.5" Canvas.Top="48" TextWrapping="Wrap" Foreground="#FF100888" Text=":" FontSize="20"/> 
  45.  
  46.         <TextBlock x:Name="Copyright" Width="88" Height="16" Canvas.Left="16" TextWrapping="Wrap" FontSize="12" Canvas.Top="22" Foreground="#FF100888" Text="郭红俊 clock" MouseLeftButtonDown="Copyright_MouseLeftButtonDown" MouseEnter="TextBlock_MouseEnter" MouseLeave="TextBlock_MouseLeave" /> 
  47.         <TextBlock x:Name="FullScreen" Width="88" Height="16" Canvas.Left="106" TextWrapping="Wrap" FontSize="12" Canvas.Top="22" Foreground="#FF100888" Text="FullScreen"  MouseEnter="TextBlock_MouseEnter" MouseLeave="TextBlock_MouseLeave" MouseLeftButtonDown="FullScreen_MouseLeftButtonDown" /> 
  48.     Canvas> 
  49.  
  50. UserControl> 

MainPage.xaml.cs 文件

  1. using System; 
  2. using System.Collections.Generic; 
  3. using System.Linq; 
  4. using System.Net; 
  5. using System.Windows; 
  6. using System.Windows.Controls; 
  7. using System.Windows.Documents; 
  8. using System.Windows.Input; 
  9. using System.Windows.Media; 
  10. using System.Windows.Media.Animation; 
  11. using System.Windows.Shapes; 
  12. using System.Windows.Threading; 
  13. using System.Windows.Browser; 
  14.  
  15. namespace ClockSilverlightApp 
  16.     public partial class MainPage : UserControl 
  17.     { 
  18.         public MainPage() 
  19.         { 
  20.             InitializeComponent(); 
  21.             dicWeek.Add(DayOfWeek.Friday, "五"); 
  22.             dicWeek.Add(DayOfWeek.Monday, "一"); 
  23.             dicWeek.Add(DayOfWeek.Saturday, "六"); 
  24.             dicWeek.Add(DayOfWeek.Sunday, "日"); 
  25.             dicWeek.Add(DayOfWeek.Thursday, "四"); 
  26.             dicWeek.Add(DayOfWeek.Tuesday, "二"); 
  27.             dicWeek.Add(DayOfWeek.Wednesday, "三"); 
  28.  
  29.         } 
  30.  
  31.         private static readonly Dictionarystring> dicWeek = new Dictionarystring>(); 
  32.  
  33.  
  34.         ///  
  35.         /// 定时更新前段显示信息事件 
  36.         ///  
  37.         ///  
  38.         ///  
  39.         private void enableClock(object sender, EventArgs e) 
  40.         { 
  41.             DateTime dt = DateTime.Now; 
  42.             this.txtMonth.Text = string.Format("{0:00}", dt.Month); 
  43.             this.txtDay.Text = string.Format("{0:00}", dt.Day); 
  44.             this.txtWeek.Text = dicWeek[dt.DayOfWeek]; 
  45.             this.txtHour.Text = string.Format("{0:00}", dt.Hour); 
  46.             this.txtMinute.Text = string.Format("{0:00}", dt.Minute); 
  47.             this.txtSecond.Text = string.Format("{0:00}", dt.Second); 
  48.  
  49.         } 
  50.  
  51.         DispatcherTimer timer = new DispatcherTimer(); 
  52.  
  53.  
  54.         private void UserControl_Loaded(object sender, RoutedEventArgs e) 
  55.         { 
  56.             enableClock(nullnull); 
  57.             timer.Interval = new TimeSpan(0,0,1); 
  58.             timer.Tick += new EventHandler(enableClock); 
  59.             timer.Start(); 
  60.         } 
  61.  
  62.         private void Copyright_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) 
  63.         { 
  64.             HtmlPage.Window.Navigate(new Uri("http://www.csdn.net/"), "new"); 
  65.         } 
  66.  
  67.         private void TextBlock_MouseEnter(object sender, MouseEventArgs e) 
  68.         { 
  69.             if (sender == nullreturn
  70.             TextBlock tb = sender as TextBlock; 
  71.             if (tb == nullreturn
  72.             // TextBlock.foreground 
  73.             tb.Foreground = new SolidColorBrush(Colors.Red); 
  74.             // TextBlock.textDecorations 
  75.             tb.TextDecorations = TextDecorations.Underline; 
  76.             tb.Cursor = Cursors.Hand; 
  77.         } 
  78.  
  79.         private void TextBlock_MouseLeave(object sender, MouseEventArgs e) 
  80.         { 
  81.             if (sender == nullreturn
  82.             TextBlock tb = sender as TextBlock; 
  83.             if (tb == nullreturn
  84.             // TextBlock.foreground 
  85.             tb.Foreground = new SolidColorBrush(Color.FromArgb(255,16,8,136)); 
  86.             // TextBlock.textDecorations 
  87.             tb.TextDecorations = null
  88.             tb.Cursor = Cursors.Arrow; 
  89.         } 
  90.  
  91.         private void FullScreen_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) 
  92.         { 
  93.             Application.Current.Host.Content.IsFullScreen = !Application.Current.Host.Content.IsFullScreen; 
  94.         } 
  95.     } 

本站热点业务

更多模板/案例展示

关于我们 | 联系我们 | 团队日志 | 网站地图 | 网站合作