JavaScript EditorDhtml editor     Free javascript download 



Main Page

The following code example modifies the OnPaint event handler to retrieve a pointer to the Graphics object for the main form. The OnPaint function is intended for a Windows Forms application, most likely created with a Visual Studio application wizard.

The image is represented by the Image class. The image data is loaded from a .jpg file using the System.Drawing.Image.FromFile method. Before the image is drawn to the form, the form is resized to accommodate the image. The drawing of the image is performed with the System.Drawing.Graphics.DrawImage method.

The Graphics and Image classes are both in the System.Drawing namespace.

NoteNote

GDI+ is included with WindowsВ XP and is available as a redistributable for WindowsВ NT 4.0 SP 6, WindowsВ 2000, WindowsВ 98, and WindowsВ Me. To download the latest redistributable, see http://go.microsoft.com/fwlink?linkid=11232. For more information, see the GDI+ SDK documentation at GDI+.

Example

В CopyCode imageCopy Code
#using <system.drawing.dll>

using namespace System;
using namespace System::Drawing;

protected:
Void Form1::OnPaint(PaintEventArgs^ pe)
{
    Graphics^ g = pe->Graphics;
    Image^ image = Image::FromFile("SampleImage.jpg");
    Form::ClientSize = image->Size;
    g->DrawImage( image, 0, 0, image->Size.Width, image->Size.Height );
}

See Also

Reference

System.Drawing

Other Resources

.NET Programming in C++



JavaScript EditorDhtml editor     Free javascript download