Search
Latest topics
PictureBox Class
Page 1 of 1
PictureBox Class
Represents a Windows picture box control for displaying an image.
For a list of all members of this type, see PictureBox Members.
System.Object
System.MarshalByRefObject
System.ComponentModel.Component
System.Windows.Forms.Control
System.Windows.Forms.PictureBox
[Visual Basic]
Public Class PictureBox
Inherits Control
[C#]
public class PictureBox : Control
[C++]
public __gc class PictureBox : public Control
[JScript]
public class PictureBox extends Control
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Remarks
Typically the PictureBox is used to display graphics from a bitmap, metafile, icon, JPEG, GIF or PNG file.
Set the Image property to the Image you want to display, either at design time or at run time. Clipping and positioning of the image in the display area is controlled by the SizeMode property which is set to values in the PictureBoxSizeMode enumeration. You can change the size of the display area at run time with the ClientSize property.
The PictureBox control is displayed by default without any borders. You can provide a standard or three-dimensional border using the BorderStyle property to distinguish the picture box from the rest of the form, even if it contains no image.
Example
[Visual Basic, C#, C++] The following example illustrates how you can set an image and resize the display area of the picture box. This example assumes that ShowMyImage is called from within an existing form, and that the System.Drawing namespace has been added to the source code for your form.
[Visual Basic]
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 Not (MyImage Is 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
[C#]
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 ;
}
[C++]
private:
Bitmap^ MyImage ;
public:
void ShowMyImage(String^ fileToDisplay, int xSize, int ySize)
{
// Sets up an image object to be displayed.
if (MyImage != 0)
{
MyImage->Dispose();
}
// Stretches the image to fit the pictureBox.
pictureBox1->SizeMode = PictureBoxSizeMode::StretchImage ;
MyImage = new Bitmap(fileToDisplay);
pictureBox1->ClientSize = System::Drawing::Size(xSize, ySize);
pictureBox1->Image = dynamic_cast(MyImage);
}
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button in the upper-left corner of the page.
Requirements
Namespace: System.Windows.Forms
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
For a list of all members of this type, see PictureBox Members.
System.Object
System.MarshalByRefObject
System.ComponentModel.Component
System.Windows.Forms.Control
System.Windows.Forms.PictureBox
[Visual Basic]
Public Class PictureBox
Inherits Control
[C#]
public class PictureBox : Control
[C++]
public __gc class PictureBox : public Control
[JScript]
public class PictureBox extends Control
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Remarks
Typically the PictureBox is used to display graphics from a bitmap, metafile, icon, JPEG, GIF or PNG file.
Set the Image property to the Image you want to display, either at design time or at run time. Clipping and positioning of the image in the display area is controlled by the SizeMode property which is set to values in the PictureBoxSizeMode enumeration. You can change the size of the display area at run time with the ClientSize property.
The PictureBox control is displayed by default without any borders. You can provide a standard or three-dimensional border using the BorderStyle property to distinguish the picture box from the rest of the form, even if it contains no image.
Example
[Visual Basic, C#, C++] The following example illustrates how you can set an image and resize the display area of the picture box. This example assumes that ShowMyImage is called from within an existing form, and that the System.Drawing namespace has been added to the source code for your form.
[Visual Basic]
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 Not (MyImage Is 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
[C#]
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 ;
}
[C++]
private:
Bitmap^ MyImage ;
public:
void ShowMyImage(String^ fileToDisplay, int xSize, int ySize)
{
// Sets up an image object to be displayed.
if (MyImage != 0)
{
MyImage->Dispose();
}
// Stretches the image to fit the pictureBox.
pictureBox1->SizeMode = PictureBoxSizeMode::StretchImage ;
MyImage = new Bitmap(fileToDisplay);
pictureBox1->ClientSize = System::Drawing::Size(xSize, ySize);
pictureBox1->Image = dynamic_cast
}
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button in the upper-left corner of the page.
Requirements
Namespace: System.Windows.Forms
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
Thu Aug 23, 2012 5:38 am by Admin
» Tuyệt kỹ cua giai
Thu Aug 23, 2012 5:36 am by Admin
» NETCAT.........
Mon Aug 13, 2012 6:35 am by Admin
» Bảo mật CSDL bằng phương pháp mã hóa.
Tue Apr 17, 2012 10:04 pm by Admin
» Hàm mã hóa MD5 bằng JavaScript
Tue Apr 17, 2012 10:03 pm by Admin
» Giá của món quà
Fri Apr 13, 2012 6:01 am by Admin
» Sẽ chỉ yêu ai?
Fri Apr 13, 2012 6:01 am by Admin
» Cách đọc bảng chữ cái!
Thu Apr 12, 2012 10:37 pm by Admin
» Gắn trojan, keylog, virus vào website, forum
Tue Apr 10, 2012 1:14 am by Admin