<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="322" Width="525">
    <Grid Height="218" Margin="0,3" HorizontalAlignment="Left" Width="517">
        <Grid.RowDefinitions>
            <RowDefinition Height="105*"/>
            <RowDefinition Height="113*"/>
        </Grid.RowDefinitions>
        <Rectangle Height="28" HorizontalAlignment="Left" Margin="64,24,0,0" Name="rectangle1" Stroke="Black" VerticalAlignment="Top" Width="0" />
        <Label Content="进度:" Height="28" HorizontalAlignment="Left" Margin="12,26,0,0" Name="label1" VerticalAlignment="Top" />
        <Button Content="开 始" Height="23" HorizontalAlignment="Left" Margin="206,123,0,-33" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" Grid.Row="1" />
        <Label Content="0%" Margin="71,24,0,53" Name="label2" HorizontalAlignment="Left" Width="46" />
        <TextBox TextWrapping ="Wrap" HorizontalAlignment="Left" Margin="12,57,0,10" Name="textBox1" Width="421"  Grid.RowSpan="2" TextChanged="textBox1_TextChanged" />
    </Grid>
</Window>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
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.Windows.Threading;
using System.Data;
using System.Data.SqlClient;

namespace WpfApplication1
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    //public partial class MainWindow : Window
    //{
    //    public MainWindow()
    //    {
    //        InitializeComponent();
    //    }

//    private void button1_Click(object sender, RoutedEventArgs e)
    //    {

//    }

//    private void textBox1_TextChanged(object sender, TextChangedEventArgs e)
    //    {

//    }
    //}
 
    public partial class MainWindow : Window
    {
      public  static double percent = 0;
      public static   int counts = 0;
      public static  int cc = 0;
      public static List<Menu> list = null;
      public static List<Menu> queryProgress()
      {
          SqlConnection conn = new SqlConnection();
          conn.ConnectionString = "Data Source=.;Initial Catalog=CompanyGZ;Integrated Security=True";
          SqlCommand cmd = new SqlCommand();
          string sql = "SELECT * FROM Menu;";
          cmd.Connection = conn;
          cmd.CommandText = sql;
          conn.Open();
          SqlDataAdapter adp = new SqlDataAdapter(cmd);
          DataSet ds = new DataSet();
          adp.Fill(ds);

DataTable dt = ds.Tables[0];
          list = new List<Menu>();
          list = DataTable2List(dt);
          counts = int.Parse(ds.Tables[0].Rows.Count.ToString());
          return list;

}

private static List<Menu> DataTable2List(DataTable dt)
      {
          if (dt.Rows.Count > 0)
          {
              List<Menu> list = new List<Menu>();
              Menu model = null;
              foreach (DataRow dr in dt.Rows)
              {
                  model = new Menu();
                  LoadEntityData(model, dr);
                  list.Add(model);
              }
              return list;
          }
          return null;
      }
      public static void LoadEntityData(Menu model, DataRow dr)
      {
          if (dr.Table.Columns.Contains("mId") && !dr.IsNull("mId"))
          {

model.Mid = int.Parse(dr["mId"].ToString());
          }
          model.MName = dr["mName"].ToString();
          model.MIsDel = Convert.ToBoolean(dr["mIsDel"]);
          model.MAddtime = Convert.ToDateTime(dr["mAddtime"]);
      }
        private delegate int BrushProcessHandle();
        public MainWindow()
        {
            InitializeComponent();
        }

Thickness tmpT;

private void button1_Click(object sender, RoutedEventArgs e)
        {
            queryProgress();
            this.rectangle1.Width = 0;
            i = 1;
            if (tmpT.Left == 0 && tmpT.Top == 0 && tmpT.Right == 0 && tmpT.Bottom == 0)
            {
                tmpT = this.label2.Margin;
            }
            else
            {
                this.label2.Margin = tmpT;
            }
            this.textBox1.Text = "do working...";
            // 注释此句将百分比将会一直在进度条头部显示
            this.label2.Margin = new Thickness(this.label2.Margin.Left - 52, this.label2.Margin.Top, this.label2.Margin.Right, this.label2.Margin.Bottom);
            // 取消注释字体颜色为白色
            //this.label2.Foreground = Brushes.White;
            // 取消注释字体为斜体
            //this.label2.FontStyle = FontStyles.Italic;
            BrushProcessBar();
           
        }

private DispatcherTimer dt;
        private int i = 1;
        private void BrushProcessBar()
        {
            dt = new DispatcherTimer();
            dt.Interval = new TimeSpan(10000);
            dt.Tick += new EventHandler(dt_Tick);
            dt.Start();
        }

protected void dt_Tick(object sender, EventArgs e)
        {
            // 纯色进度条
            //SolidColorBrush scb = new SolidColorBrush();
            //scb.Color = Color.FromRgb(63, 134, 231);

// 渐变进度条

LinearGradientBrush scb = new LinearGradientBrush(Color.FromRgb(63, 169, 233), Color.FromRgb(16, 111, 197), 0);
            this.rectangle1.Width = i++;
            this.label2.Margin = new Thickness(this.label2.Margin.Left + 1, this.label2.Margin.Top, this.label2.Margin.Right, this.label2.Margin.Bottom);
            this.rectangle1.Fill = scb;
            //if (i == 50 || i == 120 || i == 410)
            //{
            //    Thread.Sleep(200);
            //}
            //this.label2.Content = Decimal.Round(((decimal)i) / 400 * 100, 2) + "%";//i == 400

if (percent == 100)
            {
                dt.Stop();
              //  this.label2.Visibility =Visibility.Hidden;
                this.textBox1.Text += "\r\nCompleted";
            }
            else
            {

if (cc <= counts)
                {
                   cc=cc+1;
                }
                textBox1.Text = "do working...";
                for (int j = 0; j < 6; j++)
                {
                    if (cc + j >= counts)
                    {
                      
                        percent = 100;
                        this.label2.Content = ("" + Convert.ToInt16(percent) + "%");
                        return ;
                    // Decimal.Round(((cc)) / counts * 100, 2) + "%";//i == 400
                    }
                    textBox1.Text += "\n"+list[cc+j].Mid + ":" + list[cc+j].MName + ":" + list[cc+j].MIsDel + list[cc+j].MAddtime+"\n";
                    percent =Convert.ToDouble( cc )/ counts*100;
                    this.label2.Content =(""+Convert.ToInt16( percent)+ "%");//i == 400
                  
                }
           //this.textBox1.Text+=  
                if (percent == 100) return;
            }
     
        }

private void Window_Loaded(object sender, RoutedEventArgs e)
        {

}

private void textBox1_TextChanged(object sender, TextChangedEventArgs e)
        {

}

}
}

wpf 进度条 下拉的更多相关文章

  1. 织梦DedeCMS v5.7 实现导航条下拉菜单

    首先将下面这段代码贴到templets\default\footer.htm文件里(只要在此文件里就行,位置无所谓) <</span>script type='text/javasc ...

  2. WPF 进度条ProgressBar

    今天研究了一下wpf的进度条ProgressBar 1.传统ProgressBar WPF进度条ProgressBar 这个控件,如果直接写到循环里,会死掉,界面会卡死,不会有进度.需要把进度条放到单 ...

  3. WPF进度条系列②旋转小圆圈

     写在之前: 关于WPF的样式,我也是学习了很多朋友的文章才有了下面的东西,因为时间有些久远 & 备份的链接也都不在了. 所以,究竟是看过哪些文章,也是记不清楚了…… 请见谅. ------- ...

  4. WPF AutoGeneratingColumn 绑定下拉框

    WPF自动产生列,前台代码: <DataGrid x:Name="Dg" AutoGenerateColumns="True" CanUserAddRow ...

  5. C# WPF 进度条,根据读取数据显示进度条进度,根据Excel文件读取数据,进度条样式

    后台代码: //导入 private void Border_MouseLeftButtonUp_2(object sender, MouseButtonEventArgs e) { var path ...

  6. WPF进度条

    ProgressBar控件与传统WinForm使用方法完全一样,我们只需关注: Minimum——最小值,默认为0: Maximum——最大值,默认为100. Value——当前值.   关键是它的控 ...

  7. DEDECMS v5.7 完美实现导航条下拉二级菜单

    一.引言 好多人都问,织梦的下拉导航怎么做呢?其实很简单!即使你对代码一点也不熟悉,没关系! 按照我的步骤走!记住一步也不能错哦! 二.实现过程 1.首先: 将下面这段代码贴到templets\def ...

  8. c# wpf ComboBox 动态下拉框 及 动态默认值设定

    1.下拉框声明 <ComboBox x:Name="DirComboBox" Width="150" Height="18" Marg ...

  9. 继续聊WPF——进度条

    ProgressBar控件与传统WinForm使用方法完全一样,我们只需关注: Minimum——最小值,默认为0: Maximum——最大值,默认为100. Value——当前值.   关键是它的控 ...

随机推荐

  1. Convolutional Neural Networks

    卷积神经网络(Convolutional Neural Networks/ CNN/ConvNets) 卷积神经网络和普通神经网络十分相似: 组成它们的神经元都具有可学习的权重(weights)和偏置 ...

  2. 使用amaze ui模板全过程

    amaze ui基于gulp构建,所以现在安装gulp需要的环境,gulp使用npm安装,npm基于node.js 所以一切从node.js开始 1 下载对应的node.js 打开 https://n ...

  3. CPU,寄存器,一缓二缓.... RAM ROM 外部存储器等简介

    自我学习:一.线程安全日期格式化操作的几种方式:1.每次new一个新对象:public static Date parse(String date) throws ParseException { r ...

  4. windows,linux,esxi系统判断当前主机是物理机还是虚拟机?查询主机序列号命令

    参考网站:https://blog.csdn.net/yangzhenping/article/details/49996765 查序列号: http://www.bubuko.com/infodet ...

  5. 35. CentOS-6.3安装拼音输入法

    安装方法: su root yum install "@Chinese Support"      // 安装中文输入法 exit 装好后,在“系统-->首选项”就会看到有“ ...

  6. 网络软工个人作业4——Alpha阶段个人总结

    1.个人总结 (1) 类型 具体技能和面试问题 现在的回答 毕业时找工作 语言 拿手的语言 Java 软件实现 有没有在别人的代码基础上进行改进,你是怎么读懂别人的代码,你采取什么方法不影响原来的功能 ...

  7. HTML5 Canvas ( 线段的绘制 ) beginPath, moveTo, strokeStyle, stroke

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  8. 某C电面记

    昨天突然接到某C的电话面试,有点措不及防.15分钟左右的电面后,直接收到了不合适的邮件通知,那个惨~~~~~~~~~~~~~~~ 记录回答得不是很好的几个问题: 1.自动化层面,你做了什么工作,给团队 ...

  9. Webservice 返回数据集 DataSet 及Android显示数据集LiveBindings

    一.服务端 New TSoapDataModule 添加控件 TDataSetProvider,TClientDataSet,TADOQuery,TADOConnection 添加方法 functio ...

  10. vmware esxi6.5安装使用教程(图文安装)

    准备工作: 下载ESXI5.5镜像和client客户端. 将ISO写入到U盘或是刻录光盘然后启动安装. 一.开始安装 欢迎界面 协议界面 安装在本地 键盘的键入方式 设置登录密码 开始安装 重启 安装 ...