[]
Selects an object into the specified device context(DC). The new object replaces the previous object of the same type.
public nint SelectObject(nint gdiObjectHandle)
Type | Name | Description |
---|---|---|
nint | gdiObjectHandle | A nint that indicates the handle to the gdi object to be selected. |
Type | Description |
---|---|
nint | Returns the handle of the previous gdi object of the same type. |
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.
//
// 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);
}
}