基本信息
源码名称:C# 右上角透明倒计时窗口 示例源码
源码大小:0.12M
文件格式:.zip
开发语言:C#
更新时间:2017-10-12
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.Remoting.Metadata.W3cXsd2001;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
using Microsoft.Office.Core;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
namespace PowerPointTimer
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public enum WindowLocation
{
TOPLEFT,
TOPRIGHT
};
private PowerPoint.Application ppt;
private System.Timers.Timer clock;
private System.Timers.Timer pptMonitor;
private int timeLeft;
public MainWindow()
{
InitializeComponent();
this.Height = 75;
this.Background = Brushes.Transparent;
this.Closed = (sender, args) =>
{
if (ppt == null) return;
if (ppt.Presentations.Count == 0)
ppt.Quit();
GC.Collect();
};
LoadSettings();
RefreshUI();
MoveWindow((WindowLocation)SharedResource.setting.DefaultLocation);
ClockConfig();
MonitorConfig();
}
private void LoadSettings()
{
timeLeft = SharedResource.setting.CountdownLen;
}
private void RefreshUI()
{
label.Content = Helper.Time2Str(SharedResource.setting.CountdownLen);
}
private void MonitorConfig()
{
pptMonitor = new System.Timers.Timer();
pptMonitor.Elapsed = (sender, args) =>
{
if (Process.GetProcessesByName("POWERPNT").Length > 0)
{
Dispatcher.Invoke(() =>
{
AppConfig();
pptMonitor.Stop();
});
}
};
pptMonitor.Interval = 100;
pptMonitor.Start();
}
private void ClockConfig()
{
clock = new System.Timers.Timer();
clock.Elapsed = (sender, args) =>
{
Dispatcher.BeginInvoke((Action)(() =>
{
timeLeft -= 1;
label.Content = Helper.Time2Str(timeLeft);
if (timeLeft == 0) clock.Stop();
}));
};
clock.Interval = 1000;
}
private void AppConfig()
{
ppt = new PowerPoint.Application();
ppt.Visible = MsoTriState.msoTrue;
ppt.Activate();
ppt.SlideShowBegin = (window) =>
{
Dispatcher.BeginInvoke((Action)(() =>
{
timeLeft = SharedResource.setting.GetLength(window.Presentation.FullName);
label.Content = Helper.Time2Str(timeLeft);
clock.Start();
btnSettings.IsEnabled = false;
}));
};
ppt.SlideShowEnd = (window) =>
{
Dispatcher.BeginInvoke((Action) (() =>
{
clock.Stop();
btnSettings.IsEnabled = true;
}));
};
}
private void btnClose_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
private void btnSettings_Click(object sender, RoutedEventArgs e)
{
var settingWindow = new SettingWindow();
settingWindow.ShowDialog();
RefreshUI();
timeLeft = SharedResource.setting.CountdownLen;
}
private void MoveWindow(WindowLocation location)
{
switch (location)
{
case WindowLocation.TOPLEFT:
this.Left = 0;
this.Top = 0;
break;
case WindowLocation.TOPRIGHT:
this.Left = Helper.GetScreenWidth() - this.Width;
this.Top = 0;
break;
}
}
private void MainWindow_MouseDown(object sender, MouseButtonEventArgs e)
{
this.DragMove();
}
private void MainWindow_MouseEnter(object sender, MouseEventArgs e)
{
this.Height = 240;
this.Background = Brushes.White;
}
private void MainWindow_MouseLeave(object sender, MouseEventArgs e)
{
this.Height = 75;
this.Background = Brushes.Transparent;
}
}
}