国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

WPF ProgressBar實現實時進度效果

2019-10-29 19:32:17
字體:
來源:轉載
供稿:網友

本文實例為大家分享了WPF ProgressBar實現實時進度的具體代碼,供大家參考,具體內容如下

WPF,ProgressBar,實時進度

簡單測試,頁面如圖:

利用上班的一點點空閑時間,做了個wpf progressbar的例子,覺得有潛力可挖,故放上來供大家參考,有寫的更好的請留言哦,方便交流學習,謝謝

這個xaml:

<Page x:Class="WpfBrowserAppDrill.ProgressBarPage"  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"   xmlns:d="http://schemas.microsoft.com/expression/blend/2008"   mc:Ignorable="d" <Grid>  <Button Margin="10" Click="Button_Click" VerticalAlignment="Top" Height="23" Width="100">進度條控制</Button>  <TextBlock Name="txtJD" VerticalAlignment="Top" HorizontalAlignment="Center" Margin="50">當前進度:</TextBlock>  <ProgressBar Height="20" HorizontalAlignment="Center" Margin="8,167,0,0" Name="pb_import" VerticalAlignment="Top" Width="500" /> </Grid></Page>

后臺代碼:

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;using System.Threading;namespace WpfBrowserAppDrill{ /// <summary> /// ProgressBarPage.xaml 的交互邏輯 /// </summary> public partial class ProgressBarPage : Page {  public ProgressBarPage()  {   InitializeComponent();   }   private void beginImport()   {   double value = 0;   double total = 100d;//得到循環次數   while (value < total)   {    double jd = Math.Round(((value + 1) * (pb_import.Maximum / total)), 4);    pb_import.Dispatcher.Invoke(new Action<System.Windows.DependencyProperty, object>(pb_import.SetValue),     System.Windows.Threading.DispatcherPriority.Background,     ProgressBar.ValueProperty,     jd);    //這里是加數據或費時的操作,我這里讓它掛起300毫秒    Thread.Sleep(300);    txtJD.Text = "當前的進度是:" + (value + 1) + "(實際值)" + jd + "(百分比)";    value++;   }  }  private void Button_Click(object sender, RoutedEventArgs e)  {   beginImport();   ////new Thread(new ThreadStart(beginImport)).Start();  }  private void Page_Loaded(object sender, RoutedEventArgs e)  {     pb_import.Maximum = 100;   pb_import.Value = 0;   }  }}

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到c#教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 五寨县| 卓尼县| 资源县| 莫力| 利津县| 岱山县| 黔东| 湟源县| 宾川县| 九台市| 仪陇县| 禄丰县| 彭泽县| 广丰县| 鄯善县| 屏山县| 文登市| 新昌县| 乾安县| 长子县| 康马县| 泰和县| 安陆市| 深州市| 九寨沟县| 阜新市| 潜山县| 门头沟区| 始兴县| 射洪县| 泸溪县| 微山县| 伊春市| 濮阳县| 南部县| 松江区| 阿城市| 眉山市| 天镇县| 通化县| 仙游县|