用c# progressBar 控件实现进度条红绿蓝三种颜色渐变


.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 进度条显示

{

    /// <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="进度条显示.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>


柔情似水的眼眸3611166
浏览 6304回答 0
0回答
打开App,查看更多内容
随时随地看视频慕课网APP