All posts by 龙生
WPF窗体最小化到任务栏
WPF程序也可以很轻松的实现类似QQ那样最小化到任务栏的功能。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
WindowState ws; WindowState wsl; NotifyIcon notifyIcon; #region Constructions public MainWindow()();//显示托盘。 icon(); //保证窗体显示在上方。 wsl = WindowState; } #endregion private void icon() { this.notifyIcon = new NotifyIcon(); this.notifyIcon.BalloonTipText = "Hello, 文件监视器"; //设置程序启动时显示的文本 this.notifyIcon.Text = "文件监视器";//最小化到托盘时,鼠标点击时显示的文本 this.notifyIcon.Icon = new System.Drawing.Icon("Downloads.ico");//程序图标 this.notifyIcon.Visible = true; notifyIcon.MouseDoubleClick += OnNotifyIconDoubleClick; this.notifyIcon.ShowBalloonTip(1000); } private void OnNotifyIconDoubleClick(object sender, EventArgs e) { this.Show(); WindowState = wsl; } private void Window_StateChanged(object sender, EventArgs e) { ws = WindowState; if (ws == WindowState.Minimized) { this.Hide(); } } |
from:https://www.cnblogs.com/Gyoung/archive/2012/12/06/2805932.html
View DetailsWPF最小到系统托盘
让WPF应用最小到系统托盘?可以调用System.Windows.Forms.NotifyIcon来实现,下面是示例代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
public partial class MainWindow : Window { private NotifyIcon notifyIcon; public MainWindow() { InitializeComponent(); this.notifyIcon = new NotifyIcon(); this.notifyIcon.BalloonTipText = "系统监控中... ..."; this.notifyIcon.ShowBalloonTip(2000); this.notifyIcon.Text = "系统监控中... ..."; this.notifyIcon.Icon = new System.Drawing.Icon(@"AppIcon.ico"); this.notifyIcon.Visible = true; //打开菜单项 System.Windows.Forms.MenuItem open = new System.Windows.Forms.MenuItem("Open"); open.Click += new EventHandler(Show); //退出菜单项 System.Windows.Forms.MenuItem exit = new System.Windows.Forms.MenuItem("Exit"); exit.Click += new EventHandler(Close); //关联托盘控件 System.Windows.Forms.MenuItem[] childen = new System.Windows.Forms.MenuItem[] { open, exit }; notifyIcon.ContextMenu = new System.Windows.Forms.ContextMenu(childen); this.notifyIcon.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler((o, e) => { if (e.Button == MouseButtons.Left) this.Show(o, e); }); } private void Show(object sender, EventArgs e) { this.Visibility = System.Windows.Visibility.Visible; this.ShowInTaskbar = true; this.Activate(); } private void Hide(object sender, EventArgs e) { this.ShowInTaskbar = false; this.Visibility = System.Windows.Visibility.Hidden; } private void Close(object sender, EventArgs e) { System.Windows.Application.Current.Shutdown(); } } |
运行时发现,程序一定要能找到ICON,否则会报错,并且ICON还没包含到程序中,需要一个额外的ICON来做托盘图标。当然这个都是能解决的:
1 |
this.notifyIcon.Icon = new System.Drawing.Icon(@"AppIcon.ico"); |
将以上一句替换成下面内容,意思就是读取程序图标,来作为托盘图标
1 |
this.notifyIcon.Icon = System.Drawing.Icon.ExtractAssociatedIcon(System.Windows.Forms.Application.ExecutablePath); |
运行,搞定,这样你的程序就不用拖着一个ICON文件当累赘了。 from:https://www.cnblogs.com/ke10/archive/2012/11/16/NotifyIcon.html
View DetailsWPF关闭应用汇总
就本人而言,C#中关闭应用主要有以下途径: 1.Close():关闭当前窗口,可以在OnClosing和 OnClosed中捕获消息,在OnClosing的时候,可以取消关闭窗口 2.Application.Current.Shutdown()/App.Current.Shutdown(): 关闭当前程序,如果有其他线程没有结束,不会关闭 3.Environment.Exit(0):强制退出,即使有其他的线程没有结束 4.Process类的CloseMainWindow, Kill:Process.CloseMainWindow是GUI程序的最友好结束方式,从名字上就可以看出来它是通过结束主窗体,相当于用户点击窗体的关闭按钮或者按Alt + F4 5.Environment类的FailFast:这是最暴力最彻底最直接的方法,一般不建议使用 现对各方式做简单的介绍: Close():如过调用了Close,而在Closing中没有显示的取消退出,则系统可以退出,这种情况仅仅是在没有多余线程,没有其他窗口启动的时候,如果有其他窗口同时启动,则要考虑App.Current.ShutdownMode。 Application.Current.Shutdown()/App.Current.Shutdown():其使用讲究最多。 在WPF应用程序的关闭是有ShutdownMode属性设置,具有3中枚举类型的值: 1)OnLastWindowClose(默认值)—应用程序最后一个窗体关闭时关闭应用程序 2)OnMainWindowClose—应用程序主窗体关闭时关闭应用程序 3)OnExplicitShutdown—显示调用关闭 示例如下: <Application x:Class="TestApplication.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation%22 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml%22 StartupUri="Window1.xaml" ShutdownMode="OnMainWindowClose"> </Application> Environment.Exit(0):Environment.Exit相当于在Main函数中的return指令。不过它不会执行代码块的finally块(如果有的话),但资源清理还是要进行的。它是最常见的退出当前进程的方法之一。在Main函数中我们可以直接return语句便退出了程序。如果不在Main函数内,那么Environment.Exit方法就可以派上用场。 示例如下: private void CloseApp() { CloseSignal(); AppManager.Instance.Close(); Environment.Exit(0); } Environment类的FailFast:此方法更速度,它甚至不需要向操作系统返回进程退出代码(ExitCode),直接结束当前进程并在应用程序事件薄中写入信息,用于程序出现致命错误需要立即停止。 Process.Kill:从名字也可以看出来,直接杀掉,不给喘息喘息机会,Kill方法会直接结束整个进程,不进行常规资源清理(什么finally块等……)。Kill本质调用本地API:TerminateProcess函数。 from:http://blog.csdn.net/nncrystal/article/details/36422785
View DetailsWPF钟表效果实现
WPF在样式定义和UI动画上面相对于以前的技术有了不少的提升,下面给出WPF技术实现钟表的效果: 1、Visual Studio新建一个WPF应用程序,命名为WpfClock,新建一个images文件夹,并准备一个钟表的背景图片和程序图标素材。 2、编辑MainWindow.xaml文件,对UI进行定制,代码如下(指针都是用Rectangle实现的,当然可以用图片代替):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
<Window x:Class="WpfClock.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Margin="2" Height="327" Width="311" AllowsTransparency="True" WindowStyle="None" Background="Transparent" WindowStartupLocation="CenterScreen" Icon="images/clock.ico" ResizeMode="NoResize" Topmost="False" Opacity="1"> <Grid Width="300" Height="300" MouseLeftButtonDown="Grid_MouseLeftButtonDown"> <Image Source="images/backGround.png"></Image> <Label Name="lab商标" Foreground="White" Margin="0,0,0,211" HorizontalAlignment="Center" VerticalAlignment="Bottom" Height="Auto" Width="Auto" FontSize="13" >JackMoon</Label> <Label Name="lab创建时间" Foreground="White" Margin="0,91,0,0" HorizontalAlignment="Center" VerticalAlignment="Top" Height="Auto" Width="Auto">1987</Label> <!-- 秒针定义 --> <Rectangle Margin="150,0,149,150" Name="rectangleSecond" Stroke="White" Height="120" VerticalAlignment="Bottom" Width="1"> <Rectangle.RenderTransform> <RotateTransform x:Name="secondPointer" CenterX="0" CenterY="120" Angle="0" /> </Rectangle.RenderTransform> </Rectangle> <!-- --> <!-- 分钟定义 --> <Rectangle Margin="150,49,149,151" Name="rectangleMinute" Stroke="LightGreen" Width="1"> <Rectangle.RenderTransform> <RotateTransform x:Name="minutePointer" CenterX="0" CenterY="100" Angle="45" /> </Rectangle.RenderTransform> </Rectangle> <!-- --> <!-- 时针定义 --> <Rectangle Margin="150,80,149,150" Name="rectangleHour" Stroke="LightYellow" Width="1"> <Rectangle.RenderTransform> <RotateTransform x:Name="hourPointer" CenterX="0" CenterY="70" Angle="90" /> </Rectangle.RenderTransform> </Rectangle> <!----> <Label Content="08:08:08" FontSize="16" Foreground="White" Height="Auto" HorizontalAlignment="Center" Margin="114,0,113,86" Name="labTime" VerticalAlignment="Bottom" Width="Auto" /> </Grid> </Window> |
3、编辑MainWindow.xaml.CS文件,对后台逻辑进行定制,代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; 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; namespace WpfClock { using System.Threading; using System.Windows.Threading; /// <summary> /// MainWindow.xaml 的交互逻辑 /// </summary> public partial class MainWindow : Window { //计时器 System.Timers.Timer timer = new System.Timers.Timer(1000); public MainWindow() { InitializeComponent(); #region 初始化时间 secondPointer.Angle = DateTime.Now.Second * 6; minutePointer.Angle = DateTime.Now.Minute * 6; hourPointer.Angle = (DateTime.Now.Hour * 30) + (DateTime.Now.Minute * 0.5); this.labTime.Content = DateTime.Now.ToString("HH:mm:ss"); #endregion timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed); timer.Enabled = true; } private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { //进行拖放移动 this.DragMove(); } private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { //UI异步更新 this.Dispatcher.Invoke(DispatcherPriority.Normal, (Action)(() => { //秒针转动,秒针绕一圈360度,共60秒,所以1秒转动6度 secondPointer.Angle = DateTime.Now.Second * 6; //分针转动,分针绕一圈360度,共60分,所以1分转动6度 minutePointer.Angle = DateTime.Now.Minute * 6; //时针转动,时针绕一圈360度,共12时,所以1时转动30度。 //另外同一个小时内,随着分钟数的变化(绕一圈60分钟),时针也在缓慢变化(转动30度,30/60=0.5) hourPointer.Angle = (DateTime.Now.Hour * 30)+ (DateTime.Now.Minute * 0.5); //更新时间值 this.labTime.Content = DateTime.Now.ToString("HH:mm:ss"); })); } } } |
4、编译运行,如果运气不错的话,应该能显示如下效果: 5、总结 WPF可以用RotateTransform中的Angle进行旋转,可以指定中心点(CenterX,CenterY)
1 2 3 |
<Rectangle.RenderTransform> <RotateTransform x:Name="hourPointer" CenterX="0" CenterY="70" Angle="90" /> </Rectangle.RenderTransform> |
from:https://www.cnblogs.com/isaboy/p/wpfclock.html
View DetailsWPF中的线程使用
简介 但凡涉及到图形界面,往往的设计都是不支持或者不推荐使用多个线程操作界面内容.而且通常会有一个专门的线程调度器来处理任务线程和界面线程的问题.下面提供两个两个方案. 使用Dispatcher.BeginInvoke 这个方法简单暴力适合小工作量的修改一些界面内容.使用Dispatcher.BeginInvoke()会将代码安排为调度程序的一个任务. 步骤 使用Thread新建并开始一个线程 在新建的线程处理函数中需要修改界面的时候获取界面的dispatcher 使用Dispatcher的BeginInvoke方法指定一个线程优先级,和一个委托,这个委托时用于修改界面内容的 下面给出一部分代码
1 2 3 |
//新建线程 Thread thread = new Thread(UpdateTextRight); thread.Start(); |
下面是新线程中的方法
1 2 3 4 5 6 7 8 9 10 |
//这个事例刚好是先窗体类中定义的,所以获取Dispatcher变得比较方便,而且使用了匿名委托.在通常的代码中会把委托给分离出去比较好. private void UpdateTextRight() { this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart) delegate() { txt.Text = "Here is some new text."; } ); } |
使用BackgroupWorker 这个类是专门用于简化Windows Form程序与线程相关的问题设计的,同样适用于WPF程序.适合于一个长期的后台进程,支持进度通知,取消支持,完成通知等功能. 使用方法也很简单,创建一个BackfruopWorker实例,它有几个事件. DoWork事件会在另外一个线程中执行,用RunWorkerAsync()启动.所以在这个事件中不要去处理修改界面的事情 RunWorkerCompleted事件,在DoWork事件返回时(正常或者异常返回),在图形的线程中执行,所以可以修改界面 ProgressChanged事件,使用ReportProgress()方法调用,同时是在图形界面的线程中执行,通常负责修改一下进度条什么的.而ReportProgress()方法,通常会在DoWork的事件中调用,然后给一个百分比的值.要使用这个功能,需要把WorkerReportsProgress属性设置成true 另外值得一说的是,要取消支持需要把WorkerSupportsCancellation属性设为true,使用CancelAsync()方法调用,但是这个调用不会终止进程,所以在DoWork事件中需要判断CancellationPending. 下面给出部分代码 创建BackgroundWorker实例
1 2 3 4 5 6 7 8 9 10 11 |
BackgroundWorker backgroundWorker; backgroundWorker = new BackgroundWorker(); backgroundWorker.DoWork += backgroundWorker_DoWork; backgroundWorker.RunWorkerCompleted += backgroundWorker_RunWorkerCompleted; //可以返回工作进度 backgroundWorker.WorkerReportsProgress = true; backgroundWorker.ProgressChanged += backgroundWorker_ProgressChanged; //允许取消 backgroundWorker.WorkerSupportsCancellation = true; |
开始执行DoWork
1 |
backgroundWorker.RunWorkerAsync(); |
DoWork事件范例,这个方法的内容是在另外一个线程,异步执行得
1 2 3 4 5 6 7 8 9 10 11 |
private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) { while(!backgroundWorker.CancellationPending) { //Do SomeThing //在合适的时候使用 //backgroundWorker.ReportProgress(i); //报告一下进度,其中i是0-100的整数 } //这里可以使用e.Result给一个返回值,如果有需要的话 } |
进度改变时的处理事件,也就是修改一下进度条什么的
1 2 3 4 |
private void backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) { progressBar.Value = e.ProgressPercentage; } |
完成事件我就不演示,下面是取消任务的方法
1 2 3 4 |
private void cmdCancel_Click(object sender, RoutedEventArgs e) { backgroundWorker.CancelAsync(); } |
https://www.cnblogs.com/atskyline/archive/2012/06/22/2558516.html
View Detailsm4a
M4A是MPEG-4 音频标准的文件的扩展名。在MPEG4标准中提到,普通的MPEG4文件扩展名是“.mp4”。自从Apple开始在它的iTunes以及 iPod中使用“.m4a”以区别MPEG4的视频和音频文件以来,“.m4a”这个扩展名变得流行了。目前,几乎所有支持MPEG4音频的软件都支持“.m4a”。
View Detailslaravel配置路由出现404解决办法
问题分析 一般出现这种情况的都是apache/nginx配置出现问题 问题解决 nginx解决办法 在location里面加上 try_files $uri $uri/ /index.php?$query_string; 如果配置文件中存在 try_files $uri $uri/ =404;需要将它注释掉或者删掉,否则会报错 本人的nginx配置(我是在域名里面进行配置的)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
server { listen 80; server_name www.onlinebook.com; root /home/developer/Desktop/www/laravel_book/public/; index index.html index.php index.htm; location / { #try_files $uri $uri/ =404; try_files $uri $uri/ /index.php?$query_string; } location ~ \.php$ { include snippets/fastcgi-php.conf; # # # With php7.0-cgi alone: # fastcgi_pass 127.0.0.1:9000; # # With php7.0-fpm: fastcgi_pass unix:/run/php/php7.0-fpm.sock; } } |
from:http://blog.csdn.net/sunxiang_520/article/details/51633837
View DetailsPowerDesigner使用教程
PowerDesigner是一款功能非常强大的建模工具软件,足以与Rose比肩,同样是当今最著名的建模软件之一。Rose是专攻UML对象模型的建模工具,之后才向数据库建模发展,而PowerDesigner则与其正好相反,它是以数据库建模起家,后来才发展为一款综合全面的Case工具。 PowerDesigner主要分为7种建模文件: 1. 概念数据模型 (CDM) 对数据和信息进行建模,利用实体-关系图(E-R图)的形式组织数据,检验数据设计的有效性和合理性。 2. 逻辑数据模型 (LDM) PowerDesigner 15 新增的模型。逻辑模型是概念模型的延伸,表示概念之间的逻辑次序,是一个属于方法层次的模型。具体来说,逻辑模型中一方面显示了实体、实体的属性和实体之间的关系,另一方面又将继承、实体关系中的引用等在实体的属性中进行展示。逻辑模型介于概念模型和物理模型之间,具有物理模型方面的特性,在概念模型中的多对多关系,在逻辑模型中将会以增加中间实体的一对多关系的方式来实现。 逻辑模型主要是使得整个概念模型更易于理解,同时又不依赖于具体的数据库实现,使用逻辑模型可以生成针对具体数据库管理系统的物理模型。逻辑模型并不是在整个步骤中必须的,可以直接通过概念模型来生成物理模型。 3. 物理数据模型 (PDM) 基于特定DBMS,在概念数据模型、逻辑数据模型的基础上进行设计。由物理数据模型生成数据库,或对数据库进行逆向工程得到物理数据模型。 4. 面向对象模型 (OOM) 包含UML常见的所有的图形:类图、对象图、包图、用例图、时序图、协作图、交互图、活动图、状态图、组件图、复合结构图、部署图(配置图)。OOM 本质上是软件系统的一个静态的概念模型。 5. 业务程序模型 (BPM) BPM 描述业务的各种不同内在任务和内在流程,而且客户如何以这些任务和流程互相影响。 BPM 是从业务合伙人的观点来看业务逻辑和规则的概念模型,使用一个图表描述程序,流程,信息和合作协议之间的交互作用。 6. 信息流模型(ILM) ILM是一个高层的信息流模型,主要用于分布式数据库之间的数据复制。 7. 企业架构模型(EAM): 从业务层、应用层以及技术层的对企业的体系架构进行全方面的描述。包括:组织结构图、业务通信图、进程图、城市规划图、应用架构图、面向服务图、技术基础框架图。 正所谓“工欲善其事必先利其器”,PowerDesigner就是一把强大的“神器”,若能运用自如,再身怀“绝世武功”,那你基本就遇神杀神遇佛杀佛了! 关于PowerDesigner物理数据模型的基本使用,我这里就不废话了,给出个连接,地球人看完都知道:http://www.cnblogs.com/huangcong/archive/2010/06/14/1757957.html 下面就一些比较高级型的用法和技巧我着重说明下。 1. 生成sql脚本 Database→Generate Database 选择要输出的文件路径,即文件存储路径,并根据需要修改文件名,单击确定后便会生成sql脚本。 在Options选项卡里,可以个性化选择和配置sql脚本,如取消外键,去除drop语句等。 Selection选项卡中可以选择哪些表要生成sql脚本。 在Preview选项卡可以预览将要生成的sql脚本。 2. 将所有名词转化为大写 tools→Model Options…→Naming Convention→Code→Uppercase。 3. 表字段设计窗口显示comment来编写注释 双击表打开表的属性窗口→Columns选项卡→单击上排倒数第二个图标(Customize Columns and Filter)→勾选comment 4. 修改表的字段Name的时候,Code不自动跟着变 tools→General Options…→Dialog→取消勾选Name to Code mirroring 5. 不同数据库之间的转化 Database→Change Current DBMS→选择要转换成的目标数据库 6. 导入sql脚本生成相应的数据库表模型图 File→Reverse Engineer→Database…→修改模块名称并选择DBMS Using script files→点击下方图标(Add Files)来添加sql脚本文件→确定 7. 由物理模型生成对象模型,并生成相应的get、set方法 tools→Generate Object-Oriented Model…→选择语言→修改Name和Code→(Selection选项卡→选择要生成对象模型的表)→确定 双击生成的某张表的类图打开属性窗口→选中全部字段→将字段Visibility全部改为private→单击下方Add…按钮→选择Get/Set Operations→确定 之后生成代码即可:Language→Generate Java Code… 【注意:不同语言Add…按钮下的内容有区别,如C#是Property】 6. […]
View DetailsKotlin
Kotlin 是一个基于 JVM 的新的编程语言,由 JetBrains 开发。 Kotlin可以编译成Java字节码,也可以编译成JavaScript,方便在没有JVM的设备上运行。 JetBrains,作为目前广受欢迎的Java IDE IntelliJ 的提供商,在 Apache 许可下已经开源其Kotlin 编程语言。 Kotlin已正式成为Android官方支持开发语言。
View Details