ComponentOne Input for WinForms
C1.Win.C1Input.4.5.2 Assembly / C1.Framework.Drawing.Gdi.DeviceContexts Namespace / DeviceContext Class / SelectObject Method
A System.IntPtr that indicates the handle to the gdi object to be selected.
Example

In This Topic
    SelectObject Method
    In This Topic
    Selects an object into the specified device context(DC). The new object replaces the previous object of the same type.
    Syntax
    'Declaration
     
    Public Function SelectObject( _
       ByVal gdiObjectHandle As System.IntPtr _
    ) As System.IntPtr
    public System.IntPtr SelectObject( 
       System.IntPtr gdiObjectHandle
    )

    Parameters

    gdiObjectHandle
    A System.IntPtr that indicates the handle to the gdi object to be selected.

    Return Value

    Returns the handle of the previous gdi object of the same type.
    Remarks
    Note: When the handle of a gdi object is selected to DeviceContext, the properties of the gdi object can not changed and the gdi object can not be disposed.
    Example
    //
    // Paints a rectangle that is single black border and filled with white.
    //
    using (Pen pen = new SolidPen(Color.Black))
    {
        using (Brush brush = new SolidBrush(Color.Wheat))
        {
            DeviceContext dc = DeviceContext.Screen;
            IntPtr defaultPenHandle = dc.SelectObject(pen.Handle);
            IntPtr defaultBrushHandle = dc.SelectObject(brush.Handle);
                
            dc.PaintRectangle(new Rectangle(0, 0, 100, 100));
                
            dc.SelectObject(defaultPenHandle);
            dc.SelectObject(defaultBrushHandle);
        }
    }
    See Also