WPF 画心2.0版之元旦快乐
2021-07-09 13:05
标签:oid type lse obj scree cti str log off 2017年元旦已经到了,想做一个祝福语的窗口,就把上一篇画心的程序改了改,变成了如下界面。 说下改动的地方,首先窗口没有标题栏了。 MainWindow.xaml 中间圆形按钮的样式 虽然没有了标题栏,为了能够让窗口自由移动 双击鼠标,关闭窗口 不再使用线程睡眠的方式来动态显示心的生成,这次采用计时器。 本次心的生成算法,基本不变,只是把心的半径和位置调整了下。 为了添加背景音乐,使用了MediaElement。 为了能够循环播放 WPF 画心2.0版之元旦快乐 标签:oid type lse obj scree cti str log off 原文地址:https://www.cnblogs.com/lonelyxmas/p/9706994.html AllowsTransparency="True"
MouseDoubleClick="Window_MouseDoubleClick"
WindowStyle="None" Background="#00FFFFFF" Loaded="Window_Loaded" MouseMove="Window_MouseMove"
Title="MainWindow" Height="700" Width="900"
private void Window_MouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
this.DragMove();
}
}
private void Window_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
this.Close();
}
private DispatcherTimer timer = new DispatcherTimer();//创建定时器对象
public MainWindow()
{
InitializeComponent();
WindowStartupLocation = WindowStartupLocation.CenterScreen;
this.bendediction.Content = "2017年\r\n元旦快乐";
timer.Tick += new EventHandler(timer_Tick); //添加事件,定时到事件
timer.Interval = TimeSpan.FromMilliseconds(100);//设置定时长
timer.Start();
}
void timer_Tick(object sender, EventArgs e)
{
if (iTick
private void CreateHeartLine(int iTick)
{
centerPt = canvas_Shape.Width/ 4;
radius = canvas_Shape.Width / 6;
for (int i = 0; i )
{
System.Windows.Controls.Image img = new System.Windows.Controls.Image();
img.Source = new BitmapImage(new Uri(@"image/" + 2 + ".png", UriKind.Relative));//给出照片路径
img.Height = 200;
img.Width = 200;
img.Stretch = Stretch.Fill;
double angle = 2 * Math.PI / maxStep * i;
//桃形心
double x = centerPt - 16 * (Math.Sin(angle) * Math.Sin(angle) * Math.Sin(angle)) * 20;//
double y = centerPt - (13 * Math.Cos(angle) - 5 * Math.Cos(2 * angle) - 2 * Math.Cos(3 * angle) - Math.Cos(4 * angle)) * 20;//
Canvas.SetLeft(img, x);
Canvas.SetTop(img, y);
canvas_Shape.Children.Add(img);
}
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
me.LoadedBehavior = MediaState.Manual; //设置为手动控制
me.UnloadedBehavior = MediaState.Manual;
string strPath = string.Format(@"{0}\data\music\bk.mp3", System.Windows.Forms.Application.StartupPath);
Uri uri = new Uri(strPath, UriKind.Relative);
me.Source = uri;
me.IsHitTestVisible = true;
me.MediaEnded += new RoutedEventHandler(me_MediaEnded);
gd.Children.Add(me);
me.Play();
}
private void me_MediaEnded(object sender, RoutedEventArgs e)
{
me.Stop();
me.Play();
}
上一篇:WPF 动画显示控件
下一篇:c#: 模态窗口最小化主窗口