- 我在Visual Studio(版本2010)中工作。
- 我想在一種形式(不同的名稱空間和類)基於另一個名稱空間和類中的變量設置進度條。您在代碼中看到的ProgressPerc變量來自另一個類(我已經使用'OtherNameSpace'指出了它。)
- 它告訴我我無法將ProgressPerc轉換爲int(因爲我無法將類型轉換爲int)。
什麼會在這裏是最優化的解決方案,我想用這個變量來表示模擬的進度在兩個不同類別之間使用後臺工作的進度條
編輯:。加入ALMBerekeningen碼這是它只是一小部分,完整的代碼在這裏顯示太多了。
謝謝!
public class ALMBerekeningen
{
public int sim;
public int Progress;
public double ProgressPerc;
this.ProgressPerc = this.sim/1000;
this.Progress = (int)Math.Round(this.Progress * 100f, 0, MidpointRounding.AwayFromZero);
}
Public class Form1: Form
{
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
ALMBerekeningen ProgressPerc;
int sims;
sims = (int)ProgressPerc;
try
{
backgroundWorker1.ReportProgress(sims);
}
catch (Exception ex)
{
backgroundWorker1.CancelAsync();
MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
progressBar1.Value = e.ProgressPercentage;
lblProgress.Text = "Completed " + progressBar1.Value.ToString() + " %";
progressBar1.Update();
}
}
@Mong Zhu我加了一部分代碼。 this.sim在ALMBerekeningen中更改並從1變爲1000. – RobinL