Representa un control de cuadro de imagen de Windows para mostrar una imagen.
Espacio de nombres: System.Windows.Forms
Ensamblado: System.Windows.Forms (en system.windows.forms.dll)
Visual Basic (Declaración)
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
<ComVisibleAttribute(True)> _
Public Class PictureBox
Inherits Control
Implements ISupportInitialize
Dim instance As PictureBox
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)]
[ComVisibleAttribute(true)]
public class PictureBox : Control, ISupportInitialize
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)]
[ComVisibleAttribute(true)]
public ref class PictureBox : public Control, ISupportInitialize
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */
/** @attribute ComVisibleAttribute(true) */
public class PictureBox extends Control implements ISupportInitialize
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)
ComVisibleAttribute(true)
public class PictureBox extends Control implements ISupportInitialize
Se suele utilizar el control PictureBox para mostrar gráficos de un archivo de mapa de bits, metarchivo, icono, JPEG, GIF o PNG.
Establezca la propiedad Image en el objeto Image que desea mostrar, ya sea en tiempo de diseño o en tiempo de ejecución. Además, puede especificar la imagen estableciendo la propiedad ImageLocation y cargar la imagen de forma sincrónica utilizando el método Load o de forma asincrónica mediante el método LoadAsync.
Nota: |
|---|
| Si desea utilizar la misma imagen en varios controles PictureBox, cree un clon de la imagen para cada control PictureBox. Obtener acceso a la misma imagen desde varios controles hace que se produzca una excepción. |
La propiedad SizeMode, establecida en los valores en la enumeración PictureBoxSizeMode, controla el recorte y la posición de la imagen en el área de presentación. Se puede cambiar el tamaño del área de presentación en tiempo de ejecución con la propiedad ClientSize.
De forma predeterminada, el control PictureBox se muestra sin bordes. Para proporcionar un borde estándar o tridimensional, utilice la propiedad BorderStyle con el fin de distinguir el cuadro de imagen del resto del formulario, incluso si no contiene ninguna imagen. El control PictureBox no se puede seleccionar, lo que significa que no puede recibir el foco de entrada.
En el ejemplo de código siguiente se ilustra cómo se puede establecer una imagen y cambiar el tamaño del área de presentación del cuadro de imagen. En este ejemplo se requiere que se llame a ShowMyImage en un formulario existente y que se haya agregado el espacio de nombres System.Drawing al código fuente del formulario.
Private MyImage As Bitmap
Public Sub ShowMyImage(fileToDisplay As String, xSize As Integer, _
ySize As Integer)
' Sets up an image object to be displayed.
If (MyImage IsNot Nothing) Then
MyImage.Dispose()
End If
' Stretches the image to fit the pictureBox.
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
MyImage = New Bitmap(fileToDisplay)
pictureBox1.ClientSize = New Size(xSize, ySize)
pictureBox1.Image = CType(MyImage, Image)
End Sub
private Bitmap MyImage ;
public void ShowMyImage(String fileToDisplay, int xSize, int ySize)
{
// Sets up an image object to be displayed.
if (MyImage != null)
{
MyImage.Dispose();
}
// Stretches the image to fit the pictureBox.
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage ;
MyImage = new Bitmap(fileToDisplay);
pictureBox1.ClientSize = new Size(xSize, ySize);
pictureBox1.Image = (Image) MyImage ;
}
Bitmap^ MyImage;
public:
void ShowMyImage( String^ fileToDisplay, int xSize, int ySize )
{
// Sets up an image object to be displayed.
if ( MyImage != nullptr )
{
delete MyImage;
}
// Stretches the image to fit the pictureBox.
pictureBox1->SizeMode = PictureBoxSizeMode::StretchImage;
MyImage = gcnew Bitmap( fileToDisplay );
pictureBox1->ClientSize = System::Drawing::Size( xSize, ySize );
pictureBox1->Image = dynamic_cast<Image^>(MyImage);
}
private Bitmap myImage;
public void ShowMyImage(String fileToDisplay, int xSize, int ySize)
{
// Sets up an image object to be displayed.
if (myImage != null) {
myImage.Dispose();
}
// Stretches the image to fit the pictureBox.
pictureBox1.set_SizeMode(PictureBoxSizeMode.StretchImage);
myImage = new Bitmap(fileToDisplay);
pictureBox1.set_ClientSize(new Size(xSize, ySize));
pictureBox1.set_Image(myImage);
} //ShowMyImage
System.Object
System.MarshalByRefObject
System.ComponentModel.Component
System.Windows.Forms.Control
System.Windows.Forms.PictureBox
Microsoft.Ink.InkPicture
Seguridad para subprocesos
Los miembros estáticos públicos (Shared en Visual Basic) de este tipo son seguros para la ejecución de subprocesos. No se garantiza que los miembros de instancias sean seguros para la ejecución de subprocesos.
Windows 98, Windows 2000 Service Pack 4, Windows CE, Windows Millennium, Windows Mobile para Pocket PC, Windows Mobile para Smartphone, Windows Server 2003, Windows XP Media Center, Windows XP Professional x64, Windows XP SP2, Windows XP Starter
Microsoft .NET Framework 3.0 es compatible con Windows Vista, Microsoft Windows XP SP2 y Windows Server 2003 SP1.
.NET Framework
Compatible con: 3.0, 2.0, 1.1, 1.0
.NET Compact Framework
Compatible con: 2.0, 1.0