diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/PictureBox.cs b/src/System.Windows.Forms/src/System/Windows/Forms/PictureBox.cs
index ac0bb86fe29..9a9a3a478c9 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/PictureBox.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/PictureBox.cs
@@ -10,6 +10,7 @@
using System.Net;
using System.Runtime.InteropServices;
using System.Threading;
+using System.Threading.Tasks;
using System.Windows.Forms.Layout;
namespace System.Windows.Forms
@@ -48,6 +49,7 @@ public class PictureBox : Control, ISupportInitialize
// Instance members for asynchronous behavior
private AsyncOperation _currentAsyncLoadOperation;
+
private string _imageLocation;
private Image _initialImage;
private Image errorImage;
@@ -555,19 +557,11 @@ public void LoadAsync()
WebRequest req = WebRequest.Create(CalculateUri(_imageLocation));
- // Invoke BeginGetResponse on a threadpool thread, as it has
- // unpredictable latency, since, on first call, it may load in the
- // configuration system (this is NCL
- (new WaitCallback(BeginGetResponseDelegate)).BeginInvoke(req, null, null);
- }
-
- ///
- /// Solely for calling BeginGetResponse itself asynchronously.
- ///
- private void BeginGetResponseDelegate(object arg)
- {
- WebRequest req = (WebRequest)arg;
- req.BeginGetResponse(new AsyncCallback(GetResponseCallback), req);
+ Task.Run(() =>
+ {
+ // Invoke BeginGetResponse on a threadpool thread, as it has unpredictable latency
+ req.BeginGetResponse(new AsyncCallback(GetResponseCallback), req);
+ });
}
private void PostCompleted(Exception error, bool cancelled)
diff --git a/src/System.Windows.Forms/tests/IntegrationTests/WinFormsControlsClassicTests/WinFormsControlsClassicTests.csproj b/src/System.Windows.Forms/tests/IntegrationTests/WinFormsControlsClassicTests/WinFormsControlsClassicTests.csproj
index 173c60492b3..d1f149d7419 100644
--- a/src/System.Windows.Forms/tests/IntegrationTests/WinFormsControlsClassicTests/WinFormsControlsClassicTests.csproj
+++ b/src/System.Windows.Forms/tests/IntegrationTests/WinFormsControlsClassicTests/WinFormsControlsClassicTests.csproj
@@ -201,6 +201,14 @@
Panels.Designer.cs
Panels.cs
+
+ PictureBoxes.cs
+ Form
+
+
+ PictureBoxes.Designer.cs
+ PictureBoxes.cs
+
PropertyGrid.cs
Form
@@ -304,6 +312,10 @@
Panels.resx
Panels.cs
+
+ PictureBoxes.resx
+ PictureBoxes.cs
+
PropertyGrid.resx
PropertyGrid.cs
@@ -364,6 +376,4 @@
-
-
\ No newline at end of file
diff --git a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/MainForm.Designer.cs b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/MainForm.Designer.cs
index 9e6185e2adf..3536d6730dd 100644
--- a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/MainForm.Designer.cs
+++ b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/MainForm.Designer.cs
@@ -52,6 +52,7 @@ private void InitializeComponent()
this.fontNameEditor = new System.Windows.Forms.Button();
this.collectionEditors = new System.Windows.Forms.Button();
this.richTextBoxes = new System.Windows.Forms.Button();
+ this.PictureBoxes = new System.Windows.Forms.Button();
this.flowLayoutPanelUITypeEditors.SuspendLayout();
this.SuspendLayout();
//
@@ -236,6 +237,7 @@ private void InitializeComponent()
this.flowLayoutPanelUITypeEditors.Controls.Add(this.fontNameEditor);
this.flowLayoutPanelUITypeEditors.Controls.Add(this.collectionEditors);
this.flowLayoutPanelUITypeEditors.Controls.Add(this.richTextBoxes);
+ this.flowLayoutPanelUITypeEditors.Controls.Add(this.PictureBoxes);
this.flowLayoutPanelUITypeEditors.Dock = System.Windows.Forms.DockStyle.Fill;
this.flowLayoutPanelUITypeEditors.FlowDirection = System.Windows.Forms.FlowDirection.TopDown;
this.flowLayoutPanelUITypeEditors.Location = new System.Drawing.Point(8, 8);
@@ -273,6 +275,16 @@ private void InitializeComponent()
this.richTextBoxes.UseVisualStyleBackColor = true;
this.richTextBoxes.Click += new System.EventHandler(this.RichTextBoxes_Click);
//
+ // PictureBoxes
+ //
+ this.PictureBoxes.Location = new System.Drawing.Point(268, 235);
+ this.PictureBoxes.Name = "PictureBoxes";
+ this.PictureBoxes.Size = new System.Drawing.Size(258, 23);
+ this.PictureBoxes.TabIndex = 19;
+ this.PictureBoxes.Text = "PictureBoxes";
+ this.PictureBoxes.UseVisualStyleBackColor = true;
+ this.PictureBoxes.Click += new System.EventHandler(this.PictureBoxes_Click);
+ //
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
@@ -311,6 +323,7 @@ private void InitializeComponent()
private System.Windows.Forms.Button fontNameEditor;
private System.Windows.Forms.Button collectionEditors;
private System.Windows.Forms.Button richTextBoxes;
+ private System.Windows.Forms.Button PictureBoxes;
}
}
diff --git a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/MainForm.cs b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/MainForm.cs
index 6ec0591b22e..23ca6382428 100644
--- a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/MainForm.cs
+++ b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/MainForm.cs
@@ -112,5 +112,10 @@ private void RichTextBoxes_Click(object sender, EventArgs e)
{
new RichTextBoxes().Show();
}
+
+ private void PictureBoxes_Click(object sender, EventArgs e)
+ {
+ new PictureBoxes().Show();
+ }
}
}
diff --git a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/MainForm.resx b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/MainForm.resx
index 667ea1506c8..1af7de150c9 100644
--- a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/MainForm.resx
+++ b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/MainForm.resx
@@ -1,5 +1,64 @@
+
@@ -58,4 +117,4 @@
System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
+
\ No newline at end of file
diff --git a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/PictureBoxes.Designer.cs b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/PictureBoxes.Designer.cs
new file mode 100644
index 00000000000..f8e4356d5be
--- /dev/null
+++ b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/PictureBoxes.Designer.cs
@@ -0,0 +1,103 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace WinformsControlsTest
+{
+ partial class PictureBoxes
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.pictureBox1 = new System.Windows.Forms.PictureBox();
+ this.btnloadImage = new System.Windows.Forms.Button();
+ this.imageUri = new System.Windows.Forms.TextBox();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
+ this.SuspendLayout();
+ //
+ // pictureBox1
+ //
+ this.pictureBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
+ | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.pictureBox1.Location = new System.Drawing.Point(11, 39);
+ this.pictureBox1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
+ this.pictureBox1.Name = "pictureBox1";
+ this.pictureBox1.Size = new System.Drawing.Size(584, 281);
+ this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
+ this.pictureBox1.TabIndex = 0;
+ this.pictureBox1.TabStop = false;
+ this.pictureBox1.LoadCompleted += new System.ComponentModel.AsyncCompletedEventHandler(this.pictureBox1_LoadCompleted);
+ this.pictureBox1.LoadProgressChanged += new System.ComponentModel.ProgressChangedEventHandler(this.pictureBox1_LoadProgressChanged);
+ //
+ // btnloadImage
+ //
+ this.btnloadImage.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+ this.btnloadImage.Location = new System.Drawing.Point(539, 9);
+ this.btnloadImage.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
+ this.btnloadImage.Name = "btnloadImage";
+ this.btnloadImage.Size = new System.Drawing.Size(56, 23);
+ this.btnloadImage.TabIndex = 1;
+ this.btnloadImage.Text = "Load";
+ this.btnloadImage.UseVisualStyleBackColor = true;
+ this.btnloadImage.Click += new System.EventHandler(this.btnloadImage_Click);
+ //
+ // imageUri
+ //
+ this.imageUri.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.imageUri.Location = new System.Drawing.Point(13, 11);
+ this.imageUri.MaxLength = 500;
+ this.imageUri.Name = "imageUri";
+ this.imageUri.Size = new System.Drawing.Size(521, 20);
+ this.imageUri.TabIndex = 0;
+ this.imageUri.Text = "https://initiate.alphacoders.com/download/wallpaper/685514/images5/jpg/2283681847" +
+ "13846/97229";
+ //
+ // PictureBoxes
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(606, 331);
+ this.Controls.Add(this.imageUri);
+ this.Controls.Add(this.btnloadImage);
+ this.Controls.Add(this.pictureBox1);
+ this.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
+ this.Name = "PictureBoxes";
+ this.Text = "Form1";
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private System.Windows.Forms.PictureBox pictureBox1;
+ private System.Windows.Forms.Button btnloadImage;
+ private System.Windows.Forms.TextBox imageUri;
+ }
+}
\ No newline at end of file
diff --git a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/PictureBoxes.cs b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/PictureBoxes.cs
new file mode 100644
index 00000000000..cb61dd81508
--- /dev/null
+++ b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/PictureBoxes.cs
@@ -0,0 +1,74 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace WinformsControlsTest
+{
+ public partial class PictureBoxes : Form
+ {
+ private const string Heading = "PictureBox tests";
+ private bool _isLoading;
+
+ public PictureBoxes()
+ {
+ InitializeComponent();
+ Text = Heading;
+ }
+
+ private void btnloadImage_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrWhiteSpace(imageUri.Text))
+ {
+ pictureBox1.Image = null;
+ if (_isLoading)
+ {
+ pictureBox1.CancelAsync();
+ }
+
+ return;
+ }
+
+ try
+ {
+ _isLoading = true;
+ pictureBox1.WaitOnLoad = false;
+ pictureBox1.LoadAsync(imageUri.Text);
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message);
+ }
+ }
+
+ private void pictureBox1_LoadCompleted(object sender, AsyncCompletedEventArgs e)
+ {
+ _isLoading = false;
+ Text = Heading;
+
+ if (e.Cancelled)
+ {
+ MessageBox.Show("Image loading cancelled");
+ }
+
+ if (e.Error != null)
+ {
+ MessageBox.Show(e.Error.Message, $"{e.Error.GetType().FullName} occurred");
+ }
+ }
+
+ private void pictureBox1_LoadProgressChanged(object sender, ProgressChangedEventArgs e)
+ {
+ Text = $"{Heading}: loading image progress: {e.ProgressPercentage}%";
+ }
+ }
+}
diff --git a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/PictureBoxes.resx b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/PictureBoxes.resx
new file mode 100644
index 00000000000..1af7de150c9
--- /dev/null
+++ b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/PictureBoxes.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/xlf/PictureBoxes.cs.xlf b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/xlf/PictureBoxes.cs.xlf
new file mode 100644
index 00000000000..a8aaeeddfc3
--- /dev/null
+++ b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/xlf/PictureBoxes.cs.xlf
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/xlf/PictureBoxes.de.xlf b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/xlf/PictureBoxes.de.xlf
new file mode 100644
index 00000000000..41247898620
--- /dev/null
+++ b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/xlf/PictureBoxes.de.xlf
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/xlf/PictureBoxes.es.xlf b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/xlf/PictureBoxes.es.xlf
new file mode 100644
index 00000000000..5a76f6afbef
--- /dev/null
+++ b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/xlf/PictureBoxes.es.xlf
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/xlf/PictureBoxes.fr.xlf b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/xlf/PictureBoxes.fr.xlf
new file mode 100644
index 00000000000..5e53b5213bf
--- /dev/null
+++ b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/xlf/PictureBoxes.fr.xlf
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/xlf/PictureBoxes.it.xlf b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/xlf/PictureBoxes.it.xlf
new file mode 100644
index 00000000000..89867fe0079
--- /dev/null
+++ b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/xlf/PictureBoxes.it.xlf
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/xlf/PictureBoxes.ja.xlf b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/xlf/PictureBoxes.ja.xlf
new file mode 100644
index 00000000000..561fadf6b8f
--- /dev/null
+++ b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/xlf/PictureBoxes.ja.xlf
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/xlf/PictureBoxes.ko.xlf b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/xlf/PictureBoxes.ko.xlf
new file mode 100644
index 00000000000..485d4b87356
--- /dev/null
+++ b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/xlf/PictureBoxes.ko.xlf
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/xlf/PictureBoxes.pl.xlf b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/xlf/PictureBoxes.pl.xlf
new file mode 100644
index 00000000000..b71bd1bce69
--- /dev/null
+++ b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/xlf/PictureBoxes.pl.xlf
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/xlf/PictureBoxes.pt-BR.xlf b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/xlf/PictureBoxes.pt-BR.xlf
new file mode 100644
index 00000000000..c43c9dfc34b
--- /dev/null
+++ b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/xlf/PictureBoxes.pt-BR.xlf
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/xlf/PictureBoxes.ru.xlf b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/xlf/PictureBoxes.ru.xlf
new file mode 100644
index 00000000000..29accd336f5
--- /dev/null
+++ b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/xlf/PictureBoxes.ru.xlf
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/xlf/PictureBoxes.tr.xlf b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/xlf/PictureBoxes.tr.xlf
new file mode 100644
index 00000000000..215c3557e03
--- /dev/null
+++ b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/xlf/PictureBoxes.tr.xlf
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/xlf/PictureBoxes.zh-Hans.xlf b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/xlf/PictureBoxes.zh-Hans.xlf
new file mode 100644
index 00000000000..217882b7e9a
--- /dev/null
+++ b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/xlf/PictureBoxes.zh-Hans.xlf
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/xlf/PictureBoxes.zh-Hant.xlf b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/xlf/PictureBoxes.zh-Hant.xlf
new file mode 100644
index 00000000000..604d9d66419
--- /dev/null
+++ b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/xlf/PictureBoxes.zh-Hant.xlf
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file