当前位置: 首页 > news >正文

石家庄网站建设网站建设凡科网站投票排行榜是怎么做的

石家庄网站建设网站建设,凡科网站投票排行榜是怎么做的,官方网站下载微博,wordpress中科大字体WPF里面的消息提示一般都是MessageBox.Show()#xff0c;这种样式不是很好看#xff0c;所以就想办法重新搞了一个类似弹出消息的功能。原理很简单#xff0c;就是弹出一个新窗体#xff0c;然后等几秒窗体自动关闭。 先上效果图#xff1a; 新建一个MsgHelper.cs类这种样式不是很好看所以就想办法重新搞了一个类似弹出消息的功能。原理很简单就是弹出一个新窗体然后等几秒窗体自动关闭。  先上效果图 新建一个MsgHelper.cs类然后全局可以调用。 using System.Windows; using System.Windows.Threading;namespace WpfApp1;public static class MsgHelper {/// summary/// 弹出消息/// /summary/// param namemsg/param/// param namemsgState/parampublic static void ShowMsg(string msg, MsgState msgState MsgState.Info){//调用之前先关闭可能已打开的窗口CloseWindow();_timer new DispatcherTimer();_timer.Interval TimeSpan.FromSeconds(2);_timer.Tick _timer_Tick;_timer.Start();var mainWindow Application.Current.Windows.OfTypeMainWindow().FirstOrDefault();var window new MsgWindow(msg, msgState) { Owner mainWindow };window.Show();}/// summary/// 定时器/// /summarystatic DispatcherTimer _timer;private static void _timer_Tick(object? sender, EventArgs e){CloseWindow();}/// summary/// 关闭窗体/// /summarypublic static void CloseWindow(){if (_timer ! null){_timer.Stop();}var msgWindow Application.Current.Windows.OfTypeMsgWindow().FirstOrDefault();msgWindow?.Close();}/// summary/// 消息类型/// /summarypublic enum MsgState{Info,Success,Error} } 新建MsgWindow窗体用于显示消息。样式可以自己写的好看一点我这里就没做美化了。 MsgWindow.xaml代码如下 Window x:ClassWpfApp1.MsgWindowxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:dhttp://schemas.microsoft.com/expression/blend/2008xmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006xmlns:localclr-namespace:WpfApp1mc:IgnorabledTitleMsgWindow LoadedWindow_Loaded Height40 Width300 BackgroundTransparentShowInTaskbarFalse WindowStyleNone AllowsTransparencyTrue WindowStartupLocationCenterScreen Border BorderBrushDarkBlue BorderThickness1Grid BackgroundWhite Namegrid TextBlock Text VerticalAlignmentCenter HorizontalAlignmentCenter NametxtMsg Margin5/TextBlock/Grid/Border /Window MsgWindow.xaml.cs using System.Windows; using System.Windows.Media; using static WpfApp1.MsgHelper;namespace WpfApp1 {/// summary/// MsgWindow.xaml 的交互逻辑/// /summarypublic partial class MsgWindow : Window{private string _msg ;private MsgState _msgState MsgState.Info;public MsgWindow(string msg, MsgState msgState){InitializeComponent();_msg msg;_msgState msgState;}private void Window_Loaded(object sender, RoutedEventArgs e){txtMsg.Text _msg;switch (_msgState){case MsgState.Info:grid.Background new SolidColorBrush(Colors.LightGray);break;case MsgState.Success:grid.Background new SolidColorBrush(Colors.Green);txtMsg.Foreground new SolidColorBrush(Colors.White);break;case MsgState.Error:grid.Background new SolidColorBrush(Colors.Red);txtMsg.Foreground new SolidColorBrush(Colors.White);break;}}} }然后在调用。我这里是在主窗体里面调用的其他窗体里调用是一样的。 MainWindow.xaml代码如下 Window x:ClassWpfApp1.MainWindowxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:dhttp://schemas.microsoft.com/expression/blend/2008xmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006xmlns:localclr-namespace:WpfApp1mc:IgnorabledTitleMainWindow Height450 Width800GridGrid.RowDefinitionsRowDefinition/RowDefinition/Grid.RowDefinitionsGrid.ColumnDefinitionsColumnDefinition/ColumnDefinitionColumnDefinition/ColumnDefinitionColumnDefinition/ColumnDefinition/Grid.ColumnDefinitionsButton Contentinfo Width100 Height100 ClickButtonBase_OnClick Taginfo/ButtonButton Contentsuccess Grid.Row0 Grid.Column1 Width100 Height100 Tagsuccess ClickButtonBase_OnClick/ButtonButton Contenterror Grid.Row0 Grid.Column2 Width100 Height100 Tagerror ClickButtonBase_OnClick/Button/Grid /WindowMainWindow.xaml.cs using System.Windows; using System.Windows.Controls; using static WpfApp1.MsgHelper;namespace WpfApp1;/// summary /// Interaction logic for MainWindow.xaml /// /summary public partial class MainWindow {public MainWindow(){InitializeComponent();}private void ButtonBase_OnClick(object sender, RoutedEventArgs e){if (sender is Button btn){var tag btn.Tag.ToString();var infoType MsgState.Info;switch (tag){case info:infoType MsgState.Info;break;case success:infoType MsgState.Success;break;case error:infoType MsgState.Error;break;default:break;}MsgHelper.ShowMsg(DateTime.Now.ToString(), infoType);}} } 这里要注意一个问题在调用ShowMsg()方法有个owner要指定我这里给的是主窗体因为主窗体一般不会被关闭如果是在其他窗体里面可以把这个方法再加个参数然后调用的地方传个this就可以。 还有就是MsgWindow的窗体的ShowInTaskbar 要设置为false不然当鼠标移到任务栏的程序图标时会显示有两个窗体。 也可以将MsgWindow的Topmost设置为true这样就肯定是在最上层但是这个最上层是所有软件的最上层感觉不是很好。可以根据自己的需求来。 超时时间自己设置我这里设置的是2秒。
http://www.pierceye.com/news/547/

相关文章:

  • 网站建设流程方案如何找有需求做网站的公司
  • 神鹰网站建设公司openresty wordpress
  • iis .net 网站架设自己建个网站需要什么
  • 网站后台登录地址怎么安全网站底部友情链接
  • 高端网站建设如何收费上海网站制作建设是什么
  • 深圳市国外网站建设服务机构做韩国外贸网站
  • 嘉兴seo网站建设费用网站制作 中企动力公司
  • 怎么选择郑州网站建设怎样在网站模板上做修改
  • 云南旅游网站开发公司广州做网站的公司哪家好
  • 做便民网站都需要哪些模块WordPress自动截取
  • 营销型网站怎么收费装潢公司网站模板
  • 平邑网站制作不是做有网站都叫狠狠
  • 免费源码html网站株洲本地新闻
  • 网站每年要交钱吗贴心的合肥网站建设
  • 网站建设与管理简单么oa系统的概念
  • 南昌住房建设局网站珠海网站建设企业
  • dede企业网站带留言板后台查询怎样免费做网站视频讲解
  • 网站做百度推广需要哪些条件怎么建立公司网站费用
  • 博罗网站建设费用创造一个网页
  • 漳州网站设计制作公众号编辑器排行榜
  • 建设标准信息网站采购销售管理软件
  • 哈尔滨网站建设信息贵州建设厅网站厅长
  • 南京做网站的公司排名做房地产信息网怎么做
  • 医院网站建设合同范本公众号开发者中心
  • 有名的淘宝客网站手机设计图纸软件
  • 网站开发公司郑州电信备案网站打不开
  • 西安响应式网站wordpress中英文标题
  • 鹰潭手机网站建设wordpress仿qq空间
  • 网站的icp备案信息是什么百度竞价推广代运营公司
  • 网站美工培训课程免费看行情的软件大全下载