Tag: 进度条

C#如何使用选取框进度条加载表单?

我创建了一个只有带字幕样式的进度条的loadingForm。 在我的mainForm中我试图这样做: //before downloading loadingForm lf = new loadingForm(); lf.Show(); //start downloading //finishdownloading lf.Close(); 显示了loadingForm但没有出现进度条,表格看起来像是崩溃了。 完成下载后,loadingForm关闭,我的应用程序继续正常运行。 在loadingForm我只有: void loadingForm_Load(object sender, EventArgs e) { progressbar1.visible = true; } 我已经将progressbar1样式设置为loadingForm.design中的选取框。 我该如何解决? 感谢您的帮助。

C#WebClient使用Async并返回数据

好吧,我在使用DownloadDataAsync并将字节返回给我时遇到了问题。 这是我正在使用的代码: private void button1_Click(object sender, EventArgs e) { byte[] bytes; using (WebClient client = new WebClient()) { client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressChanged); bytes = client.DownloadDataAsync(new Uri(“http://example.net/file.exe”)); } } void DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) { double bytesIn = double.Parse(e.BytesReceived.ToString()); double totalBytes = double.Parse(e.TotalBytesToReceive.ToString()); double percentage = bytesIn / totalBytes * 100; label1.Text = Math.Round(bytesIn / 1000) […]

如何设置进度条的值

我用C#Winforms编写了一个用户控件。 在用户控件中,我有三个文本框: txtStartNumber – 输入的类型为:int。 txtEndNumber – 输入的类型为:int。 txtQuantity – iput的类型为:int。 (value = txtEndNumber – txtStartNumber) 进度条表示编号。 添加到数据库的记录及其总范围设置为等于txtQuantity。 当一个或多个记录重复时,进度条将停止。 我的问题是: 如何设置进度条的初始值? 如何管理进度条显示的进度? 我如何将其保存到数据库: for (long i = from; i < to; i++) { for (int j = 0; j < (to – from); j++) { arrCardNum[j] = from + j; string r = arrCardNum[j].ToString(); try […]

使用WebClient()计算要下载的总字节数

变量’totalBytes’始终为-1,因此我无法正确计算/更新进度条,为什么会发生这种情况? private void button1_Click(object sender, EventArgs e) { WebClient client = new WebClient(); client.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed); client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged); client.DownloadFileAsync(new Uri(“http://example.com/test.mp3″), @”E:\Test.mp3”); } private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e) { double bytesIn = double.Parse(e.BytesReceived.ToString()); label1.Text = Convert.ToString(bytesIn); double totalBytes = double.Parse(e.TotalBytesToReceive.ToString()); //stays at -1 label2.Text = Convert.ToString(totalBytes); double percentage = bytesIn / totalBytes […]

C#进度条 – 无法绕过它

我有一个程序,它循环文件夹中的文件,在其他地方使用该文件名创建一个新文件夹,然后将一个公共文件放在该文件夹中。 冲洗重复,直到我们完成该文件夹中的什么(列在列表框中)。 我觉得我想要看上去并且有进度条。 我在概念上理解我为每次迭代增加了一个计数(到listbox.items.count )..我编码并运行良好。 我也明白DoWork事件对于进度条来说是重要的,我如何让两者进行网格划分? 我是否每次迭代都会将计数器传递给DoWork ? 我只是错过了从主代码循环到DoEvents计数器的桥梁。

使用xaml在windws 8应用程序中从页面导航到另一个时添加进度条

我正在开发一个Windows 8应用程序,我想在从一个导航到另一个页面时向我的页面添加一个进度条,因为用户必须等待才能从服务器加载数据。 任何人都可以向我提供我需要在XAML和C#中添加的代码吗? 应该使用进度条的哪些属性或事件? // XAML PAGE <!– –> //C# Page using App1.Data; using App1.DataService; using System; using System.Collections.Generic; using System.IO; using System.Linq; using Windows.Foundation; using Windows.Foundation.Collections; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Controls.Primitives; using Windows.UI.Xaml.Data; using Windows.UI.Xaml.Input; using Windows.UI.Xaml.Media; using Windows.UI.Xaml.Navigation; // The Grouped Items Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234231 namespace App1 { […]

跨线程操作无效:从创建的线程以外的线程访问控制’label1′

可能重复: 为什么我会收到此错误:“跨线程操作无效:控制从其创建的线程以外的线程访问的lbFolders。”? 我是winforms的新手。在我的代码中,我正在使用for循环更新进度条,现在我需要以循环计数的forms更新Label,如下所示 – public partial class Form1:Form {public Form1(){InitializeComponent(); Shown += new EventHandler(Form1_Shown); // To report progress from the background worker we need to set this property backgroundWorker1.WorkerReportsProgress = true; // This event will be raised on the worker thread when the worker starts backgroundWorker1.DoWork += new DoWorkEventHandler(backgroundWorker1_DoWork); // This event will be raised […]

为什么异步ProgressBar上的文本会闪烁?

我想在ProgressBar上显示文本,( 没有 自定义进度条的所有废话)。 这并不难,并且不涉及OnPaint方法 – 如下面代码的button1所示。 但是,此方法会阻止UI线程,这是邪恶的 。 不幸的是,我最好采用异步方法导致文本闪烁,这非常烦人。 有人可以告诉我如何在没有闪烁的情况下异步更新文本吗? (要运行以下代码,只需将其粘贴到包含带有3个按钮和3个ProgressBars的Form的新项目中)。 using System; using System.Drawing; using System.Windows.Forms; using System.Threading.Tasks; using System.Threading; namespace ProgBarTest //change namespace in Program.cs accordingly { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { //This method will block the main UI […]

C#中的进度条和后台工作者

目前我正在开发一个需要从Web服务中消耗大量数据的项目。有服务类向服务器发送输入日期并返回结果,由于耗时的过程,需要用户组合进度条和后台工作者向用户显示进程百分比。 我已经浏览了很多关于这个主题的示例代码,但仍然无法找到最佳方法。 你能帮忙吗,我的代码是关注的, private MyCollection[] callWebService(string[] Inputs, string method) { List results = new List(); string fiel dNames = “”; // todo – fix this if nothing left in loop int sizeOfArray = 500; for (int i = 0; i < Inputs.Length; i = i + sizeOfArray) { string[] outputRecords; int errorCode; string errorString; string[] […]

如何更改WPF进度条上的颜色

我有一个WPF,vista样式进度条,我想更改画笔。 我已经将前景画笔设置为另一种颜色,但是有一种嗖嗖的动画效果,其颜色仍然是默认的绿色。 我怎么能改变这个?