我在這裏有一種情況。我有一個Windows窗體中的圖片框,我讓用戶通過使用openfileupload控件瀏覽圖片,之後,我將選定的圖片設置爲圖片框。這裏是我的代碼:上傳圖片時顯示ProgressBar(Windows Form C#)
namespace Employee_Card_Manager
{
public partial class Form1 : Form
{
string Chosen_File = "";
public Form1()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
selectpic.Title = "Browse Employee Picture!";
selectpic.InitialDirectory = System.Environment.GetFolderPath(Environment.SpecialFolder.Personal);
selectpic.FileName = "";
selectpic.Filter = "JPEG Images|*.jpg|GIF Images|*.gif|BITMAPS|*.bmp";
if (selectpic.ShowDialog() != DialogResult.Cancel)
{
progressBar1.Enabled = true;
Chosen_File = selectpic.FileName;
pictureBox1.Image = Image.FromFile(Chosen_File);
progressBar1.Enabled = false;
}
}
}
}
它可以正常使用!我需要對此代碼添加一些修改,以便當用戶瀏覽圖片並按下打開按鈕時,我的應用程序會向他顯示一個進度條,表明此圖片正在同時上傳... 我發現下面的代碼顯示進度條:
namespace ProgressBarSampleCSharp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void CreateButton_Click(object sender, EventArgs e)
{
ProgressBar pBar = new ProgressBar();
pBar.Location = new System.Drawing.Point(20, 20);
pBar.Name = "progressBar1";
pBar.Width = 200;
pBar.Height = 30;
//pBar.Dock = DockStyle.Bottom;
pBar.Minimum = 0;
pBar.Maximum = 100;
pBar.Value = 70;
Controls.Add(pBar);
}
}
}
,但我不知道如何適應這個代碼到我的類,以便它會在平均時間顯示進度條的圖片被上傳時! 有什麼想法?
你的問題還不清楚。 「上傳」意味着什麼?我瞭解上傳的行爲是通過電報發送到遠程位置的行爲。你的意思是'將圖像加載到圖片框'? – Steve 2012-02-25 16:50:36
需要多長時間才能在PictureBox中顯示圖像?我很驚訝,甚至需要一個進度條。 – SuperOli 2012-02-25 16:56:24
@Steve是的,我絕對的意思是將圖像加載到圖片框中。 – Azeem 2012-02-25 17:37:04