[]
        
(Showing Draft Content)

C1.Framework.Drawing.Gdi.DeviceContexts.DeviceContext.SelectObject

SelectObject Method

SelectObject(nint)

Selects an object into the specified device context(DC). The new object replaces the previous object of the same type.

Declaration
public nint SelectObject(nint gdiObjectHandle)
Parameters
Type Name Description
nint gdiObjectHandle

A nint that indicates the handle to the gdi object to be selected.

Returns
Type Description
nint

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.

Examples
//
// 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);
    }
}