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

## Content

<div class="doc-site-dotnet-api-container">



<h1 id="C1_Framework_Drawing_Gdi_DeviceContexts_DeviceContext_SelectObject_" data-uid="C1.Framework.Drawing.Gdi.DeviceContexts.DeviceContext.SelectObject*">SelectObject Method
</h1>
<div class="markdown level0 summary"></div>
<div class="markdown level0 conceptual"></div>



<a id="C1_Framework_Drawing_Gdi_DeviceContexts_DeviceContext_SelectObject_" data-uid="C1.Framework.Drawing.Gdi.DeviceContexts.DeviceContext.SelectObject*"></a>
<h4 id="C1_Framework_Drawing_Gdi_DeviceContexts_DeviceContext_SelectObject_System_IntPtr_" data-uid="C1.Framework.Drawing.Gdi.DeviceContexts.DeviceContext.SelectObject(System.IntPtr)">SelectObject(IntPtr)</h4>
<div class="markdown level1 summary"><p>Selects an object into the specified device context(DC). The new object replaces the previous
object of the same type.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public IntPtr SelectObject(IntPtr gdiObjectHandle)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Public Function SelectObject(gdiObjectHandle As IntPtr) As IntPtr</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Name</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.intptr">IntPtr</a></td>
      <td><span class="parametername">gdiObjectHandle</span></td>
      <td><p>A <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.intptr">IntPtr</a> that indicates the handle to the gdi object to be selected.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 class="returns">Returns</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.intptr">IntPtr</a></td>
      <td><p>Returns the handle of the previous gdi object of the same type.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 id="C1_Framework_Drawing_Gdi_DeviceContexts_DeviceContext_SelectObject_System_IntPtr__remarks">Remarks</h5>
<div class="markdown level1 remarks"><p>Note: When the handle of a gdi object is selected to <a class="xref" href="C1.Framework.Drawing.Gdi.DeviceContexts.DeviceContext.html">DeviceContext</a>, the properties
of the gdi object can not changed and the gdi object can not be disposed.</p>
</div>
<h5 id="C1_Framework_Drawing_Gdi_DeviceContexts_DeviceContext_SelectObject_System_IntPtr__examples">Examples</h5>
<pre><code class="lang-csharp">//
// 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);
    }
}</code></pre>

</div>
