다음을 통해 공유


PictureBox 클래스

이미지를 표시할 Windows PictureBox 컨트롤을 나타냅니다.

네임스페이스: System.Windows.Forms
어셈블리: System.Windows.Forms(system.windows.forms.dll)

구문

‘선언
<ComVisibleAttribute(True)> _
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
Public Class PictureBox
    Inherits Control
    Implements ISupportInitialize
‘사용 방법
Dim instance As PictureBox
[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] 
public class PictureBox : Control, ISupportInitialize
[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)] 
public ref class PictureBox : public Control, ISupportInitialize
/** @attribute ComVisibleAttribute(true) */ 
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */ 
public class PictureBox extends Control implements ISupportInitialize
ComVisibleAttribute(true) 
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) 
public class PictureBox extends Control implements ISupportInitialize

설명

일반적으로 PictureBox는 비트맵, 메타 파일, 아이콘, JPEG, GIF 또는 PNG 파일의 그래픽을 표시하는 데 사용됩니다.

Image 속성을 디자인 타임 또는 런타임에 표시할 Image로 설정합니다. 또는 ImageLocation 속성을 설정하여 이미지를 지정한 다음 Load 메서드를 사용하여 동기식으로 이미지를 로드하거나 LoadAsync 메서드를 사용하여 비동기식으로 이미지를 로드할 수 있습니다. PictureBoxSizeMode 열거형의 값으로 설정되는 SizeMode 속성은 표시 영역에 이미지를 클리핑하고 배치하는 작업을 제어합니다. ClientSize 속성을 사용하여 런타임에 표시 영역의 크기를 변경할 수 있습니다.

기본적으로 PictureBox 컨트롤은 테두리 없이 표시됩니다. BorderStyle 속성을 사용하여 표준 또는 3차원 테두리를 제공하면 그림 상자를 폼의 나머지 부분과 구별할 수 있습니다. 이미지가 포함되어 있지 않은 경우에도 해당됩니다. PictureBox는 선택할 수 없는 컨트롤, 즉 입력 포커스를 받을 수 없는 컨트롤입니다.

예제

다음 코드 예제에서는 이미지를 설정하고 그림 상자의 표시 영역을 조정할 수 있는 방법을 보여 줍니다. 이 예제에서는 기존 폼 내에서 ShowMyImage가 호출되고 System.Drawing 네임스페이스가 폼의 소스 코드에 추가되었다고 가정합니다.

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

스레드로부터의 안전성

이 형식의 모든 public static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.

플랫폼

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0, 1.0에서 지원

참고 항목

참조

PictureBox 멤버
System.Windows.Forms 네임스페이스