Export (0) Print
Expand All

Graphics.DrawIconUnstretched Method

Draws the image represented by the specified Icon object without scaling the image.

[Visual Basic]
Public Sub DrawIconUnstretched( _
   ByVal icon As Icon, _
   ByVal targetRect As Rectangle _
)
[C#]
public void DrawIconUnstretched(
 Icon icon,
 Rectangle targetRect
);
[C++]
public: void DrawIconUnstretched(
 Icon* icon,
 Rectangle targetRect
);
[JScript]
public function DrawIconUnstretched(
   icon : Icon,
 targetRect : Rectangle
);

Parameters

icon
Icon object to draw.
targetRect
Rectangle structure that specifies the location and size of the resulting image. The image is not scaled to fit this rectangle, but retains its original size. If the image is larger than the rectangle, it is clipped to fit inside it.

Return Value

This method does not return a value.

Example

[Visual Basic, C#] The following example is designed for use with Windows Forms, and it requires PaintEventArgs e, which is a parameter of the Paint event handler. The code performs the following actions:

  • Creates an icon from a standard Windows icon file SampIcon.ico in the example folder.
  • Creates a rectangle in which to draw the icon.
  • Draws the icon to the screen.

[Visual Basic, C#] The position of the rectangle locates the icon on the screen, and the drawn icon is unscaled and unclipped.

[Visual Basic] 
Public Sub DrawIconUnstretchedRectangle(e As PaintEventArgs)
' Create icon.
Dim newIcon As New Icon("SampIcon.ico")
' Create rectangle for icon.
Dim rect As New Rectangle(100, 100, 200, 200)
' Draw icon to screen.
e.Graphics.DrawIconUnstretched(newIcon, rect)
End Sub
        
[C#] 
public void DrawIconUnstretchedRectangle(PaintEventArgs e)
{
// Create icon.
Icon newIcon = new Icon("SampIcon.ico");
// Create rectangle for icon.
Rectangle rect = new Rectangle( 100, 100, 200, 200);
// Draw icon to screen.
e.Graphics.DrawIconUnstretched(newIcon, rect);
}
        

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

Graphics Class | Graphics Members | System.Drawing Namespace

Show:
© 2014 Microsoft