Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Does anyone know how if there is an easy way to substitute in .NET VB6 windows DC Handles, i.e properties like Form.hdc, PictureBox.hdc, etc? I need it for BitBlt and some other API functions that expect HDC for both source and destination Device Contexts.

 

Thank You.

  • *Gurus*
Posted

As provided by the .NET SDK.

<System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")>  _
Private Shared Function Rectangle(hdc As IntPtr, _
ulCornerX As Integer, ulCornerY As Integer, lrCornerX As Integer, _
lrCornerY As Integer) As Boolean
End Function

Public Sub GetHdcForGDI(e As PaintEventArgs)
    ' Create pen.
    Dim redPen As New Pen(Color.Red, 1)
    ' Draw rectangle with GDI+.
    e.Graphics.DrawRectangle(redPen, 10, 10, 100, 50)
    ' Get handle to device context.
    Dim hdc As IntPtr = e.Graphics.GetHdc()
    ' Draw rectangle with GDI using default pen.
    Rectangle(hdc, 10, 70, 110, 120)
    ' Release handle to device context.
    e.Graphics.ReleaseHdc(hdc)
End Sub

Posted

Derek, I am relatively new in .NET, I can't see how can I use this example for something like picture box control or a form, not a bitmap object or client rectangle in memory.

 

Thank you.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...