八段锦真的不错,可以练练,B站上选那种带呼吸版的
网上下的一些小程序,达不到自己想要的效果,要么就是功能复杂,于是选择了自己开发。
图片来源于给小孩买的挂贴,贴墙上看的。于是自己网上找了图片当成锁屏图片使用了。稍微看看,总比一起盯着代码要好,不建议长时间看,那样的话眼睛还是没离开显示器,久坐提醒主要是提醒起来走走动动
采用WPF 基于HandyControl 开发的小程序。
默认50分钟休息10分钟,按整点算(强迫症),如果工作不足10分钟,则将时间加到下一轮中。
取消整点勾选,从开始时计划
开始后右下角有小球球,显示倒计时,像360那样的窗口悬停吸附不知道怎么做,没继续研究
距休息10秒时,窗体会显示到最上层,同时字体颜色变为黄色
从网上找的护眼图片,可以照着练练,再起来走一走。按ESC退出 或者时间到了继续下一轮倒计时
不建议看的时间太长,因为那样的话,你的眼睛还是没有离开电脑
设置界面、倒计时、休息界面,三个页面,通过 VmReminder 进行数据共享
依赖库
这是基本框架,参考Office设计,右上解可扩展【设置】、【帮助】功能,可用于其它项目
设置工作时长、休息时长,默认从整点开始计时(有强迫症)
MainWindow.xaml
private void BtnStart_OnClick(object sender, RoutedEventArgs e)
{
_vm.IsHourly = chkHourly.IsChecked.HasValue && chkHourly.IsChecked.Value;
_vm.WorkValue = (int)numWork.Value;
_vm.BreakValue = (int)numBreak.Value;
//开始后,调用倒计时窗体,并将倒计时窗体设为主窗体,否则点拖盘图标,会弹出设置窗体
CountDown countDown = new CountDown();
countDown.DataContext = this._vm;
countDown.InitData();
Application.Current.MainWindow = countDown;
countDown.Show();
this.Close();
}
窗口倒计时时,显示在窗口右下角,
CountDown.xml
托盘图标--放在这个窗体下的原因,是因为 休息转工作时,避免托盘下会出现多个图标
<hc:NotifyIcon x:Name="NotifyIcon" Click="NotifyIconContextContent_OnClick"
Text="久坐提醒"
Visibility="Visible"
Icon="/Application.ico">
<hc:NotifyIcon.ContextMenu>
<ContextMenu>
<MenuItem Click="Settings_OnClick" Header="设置"/>
<MenuItem Click="Exit_OnClick" Header="退出"/>
</ContextMenu>
</hc:NotifyIcon.ContextMenu>
<hc:Interaction.Triggers>
<hc:EventTrigger EventName="Click">
<!--<hc:EventToCommand Command="hc:ControlCommands.PushMainWindow2Top"/>-->
</hc:EventTrigger>
</hc:Interaction.Triggers>
</hc:NotifyIcon>
WPF StringFormat="{}{0:0#}:{1:0#}" 显示倒计时,格式化,如果个位数时,前面补0
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" >
<TextBlock HorizontalAlignment="Center" Margin="5" Style="{StaticResource TextBlockLargeBold}" Foreground="White">
<TextBlock.Text>
<MultiBinding StringFormat="{}{0:0#}:{1:0#}">
<Binding Path="CountDownWorkMinute" />
<Binding Path="CountDownWorkSecond" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</StackPanel>
/// <summary>
/// 窗口显示在右下角
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CountDown_Loaded(object sender, System.Windows.RoutedEventArgs e)
{
var desktopWorkingArea = System.Windows.SystemParameters.WorkArea;
this.Left = desktopWorkingArea.Right - this.Width;
this.Top = desktopWorkingArea.Bottom - this.Height;
}
通过定时器,工作实现倒计时功能
private void Timer_OnTick(object sender, EventArgs e)
{
Remind();
//倒计时时结束,弹出休息窗口
if (_vm.CountDownWorkMinute == 0 && _vm.CountDownWorkSecond == 0)
{
_timer.Stop();
NotifyIcon.Visibility = Visibility.Hidden;
WorkBreak workBreak = new WorkBreak();
Application.Current.MainWindow = workBreak;
workBreak.DataContext = this._vm;
workBreak.InitData();
workBreak.ShowDialog();
this.Close();
return;
}
//如果分钟大于0,秒=0,那分-1,秒>0 秒-1
if (_vm.CountDownWorkMinute > 0)
{
if (_vm.CountDownWorkSecond > 0)
{
_vm.CountDownWorkSecond--;
}
else
{
_vm.CountDownWorkMinute--;
_vm.CountDownWorkSecond = 60;
}
}
if (_vm.CountDownWorkMinute == 0)
{
_vm.CountDownWorkSecond--;
}
}
休息窗体显示两护眼张图片和一个休息到计时,按ESC时可取消本次休息,
WorkBreak.xaml
<base:BaseWindow x:Class="VipReminder.Views.WorkBreak"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:base="clr-namespace:Base.Base"
mc:Ignorable="d" KeyDown="WorkBreak_OnKeyDown"
Title="WorkBreak" Height="450" Width="800">
<DockPanel Background="#00a54f">
<DockPanel Dock="Bottom" >
<TextBlock HorizontalAlignment="Center" Margin="5" Style="{StaticResource TextBlockLargeBold}" Foreground="White">
<TextBlock.Text>
<MultiBinding StringFormat="{}{0:0#}:{1:0#}">
<Binding Path="CountDownBreakMinute" />
<Binding Path="CountDownBreakSecond" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</DockPanel>
<DockPanel Dock="Left">
<Image Source="/Styles/Images/001.jpg"/>
</DockPanel>
<DockPanel Dock="Right">
<Image Source="/Styles/Images/002.jpg"/>
</DockPanel>
</DockPanel>
</base:BaseWindow>
WorkBreak.xaml.cs
namespace VipReminder.Views
{
/// <summary>
/// WorkBreak.xaml 的交互逻辑
/// </summary>
public partial class WorkBreak
{
// 定时器
private DispatcherTimer _timer;
public VmReminder _vm;
public WorkBreak()
{
InitializeComponent();
WindowState = WindowState.Maximized; //全屏显示
ShowInTaskbar = false; //任务栏不显示图标
Topmost = true; //窗体最前端显示
//this.countDown = countDown; == TODO CountDown 单例
}
private void WorkBreak_OnKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Escape)//Esc键
{
OpenCountDown();
}
}
private void OpenCountDown()
{
CountDown countDown = new CountDown();
Application.Current.MainWindow = countDown;
countDown.DataContext = this._vm;
countDown.InitData();
countDown.Show();
_timer.Stop();
this.Close();
}
public void InitData()
{
_vm = DataContext as VmReminder;
this.ShowInTaskbar = false; //任务栏不显示图标
_vm.CountDownBreakMinute = _vm.BreakValue;
_vm.CountDownBreakSecond = 0;
_timer = new DispatcherTimer();
_timer.Tick += Timer_OnTick;
_timer.Interval = TimeSpan.FromSeconds(1);
_timer.Start();
//KeyboardBlocker.off();//锁键盘
}
private void Timer_OnTick(object sender, EventArgs e)
{
//倒计时时结束,弹出休息窗口
if (_vm.CountDownBreakMinute == 0 && _vm.CountDownBreakSecond == 0)
{
_timer.Stop();
OpenCountDown();
return;
}
//如果分钟大于0,秒=0,那分-1,秒>0 减秒
if (_vm.CountDownBreakMinute > 0)
{
if (_vm.CountDownBreakSecond > 0)
{
_vm.CountDownBreakSecond--;
}
else
{
_vm.CountDownBreakMinute--;
_vm.CountDownBreakSecond = 60;
}
}
if (_vm.CountDownBreakMinute == 0)
{
_vm.CountDownBreakSecond--;
}
}
}
}
程序下载:https://gitee.com/VipSoft/Reminder/releases/download/V1.0/VipReminder.zip
源码地址:https://gitee.com/VipSoft/Reminder
眼肌运动高清图下载