.cs源碼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 進(jìn)度條顯示{? ? /// <summary>? ? /// MainWindow.xaml 的交互邏輯? ? /// </summary>? ? public partial class MainWindow : Window? ? {? ? ? ? public MainWindow()? ? ? ? {? ? ? ? ? ? InitializeComponent();? ? ? ? }? ? ? ? private delegate void A(System.Windows.DependencyProperty dp, object value);? ? ? ? private void process()? ? ? ? {? ? ? ? ? ? pro.Minimum = 0;? ? ? ? ? ? pro.Maximum = 10000;? ? ? ? ? ? pro.Value = 0;? ? ? ? ? ? double x = 0;? ? ? ? ? ? A update = new A(pro.SetValue);? ? ? ? ? ? do? ? ? ? ? ? {? ? ? ? ? ? ? ? x = x + 1;? ? ? ? ? ? ? ? Dispatcher.Invoke(update, System.Windows.Threading.DispatcherPriority.Background, new object[] { ProgressBar.ValueProperty, x });? ? ? ? ? ? ? ? lab.Content= (pro.Value * 100 / pro.Maximum).ToString()+"%";? ? ? ? ? ? ? ??? ? ? ? ? ? } while (pro.Value != pro.Maximum); ?? ? ? ? }? ? ? ? private void button1_Click(object sender, RoutedEventArgs e)? ? ? ? {? ? ? ? ? ? process();? ? ? ? ? ? pro.Foreground=? ? ? ? }? ? }}xaml源碼<Window x:Class="進(jìn)度條顯示.MainWindow"? ? ? ? xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"? ? ? ? xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"? ? ? ? Title="MainWindow" Height="350" Width="525">? ? <Grid>? ? ? ? <Button Content="start" Height="23" HorizontalAlignment="Left" Margin="175,160,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />? ? ? ? <Label Height="28" HorizontalAlignment="Left" Margin="441,81,0,0" Name="lab" VerticalAlignment="Top" />? ? ? ? <ProgressBar Height="30" HorizontalAlignment="Left" Margin="97,79,0,0" Name="pro" VerticalAlignment="Top" Width="313" />? ? </Grid></Window>
用c# progressBar 控件實(shí)現(xiàn)進(jìn)度條紅綠藍(lán)三種顏色漸變
柔情似水的眼眸3611166
2017-05-08 17:06:46