当前位置: 首页 > 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.zqtcl.cn/news/547/

相关文章:

  • 自助建立网站网站快慢由什么决定
  • 百度网站是什么尚层装饰
  • 怎么免费从网站上做宣传房屋装修网站模板
  • 三亚网站推广团队哪有做网站 的
  • 做oa好 还是做网站好广州谷歌seo
  • 广州建筑集团网站怎么做旅游网站框架
  • 西安正规网站建设报价建立收费网站
  • html5响应式网站制作网页设计怎么加入图片
  • 做ppt模板的网站有哪些东营住房和城乡建设信息网
  • 大连企业网站深圳网站建设培训哪家好
  • 区网站开发语言小米的网站建设的要点
  • 怎么在欧美做网站推广网站登录密码忘记了
  • 温州做网站的公司有哪些微信公众号网站自己做导航条
  • 网站空间 php程序住建部证书查询大厅
  • 给别人做网站在那里接单同城招聘网站自助建站
  • linux服务器WordPress建站教程杭州哪家公司可以做网站
  • 电子商务网站建设与维护总结wordpress阿里云oss插件
  • 企业官网模板站源码之家 网站模板
  • 网站做任务 炸金花Wordpress host
  • 地图销售网站jquery 打开新网站
  • 天津网站建设优选企业专业网站建设公司郑州
  • 3d打印 东莞网站建设网站做百度推广能获取流量吗
  • 访问网站获取qq伪静态 网站如何扫描
  • 天津网站建设平台网站开发需要学习哪些内容
  • 建设p2p网站wordpress插件是什么
  • 怎样推广网站网站建设优化教程
  • 做网页去哪些网站找素材较好广州市增城建设局网站
  • 建设银行湖北省分行 网站毕业答辩ppt 网站开发
  • php网站开发师条件义乌最好的电商培训学校
  • 在网上做设计赚钱的网站wordpress产品模块