DC Handle

Vitaly

Member
Joined
Nov 8, 2002
Messages
12
Location
Baltimore, MD
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.
 
As provided by the .NET SDK.
Code:
<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
 
Derek, I am relatively new in .NET, I cant 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.
 
Code:
Dim g As Graphics
g = PictureBox1.CreateGraphics()
MessageBox.Show(g.GetHdc.ToString(), Application.ProductName)
 
Tools -> Options -> Text Editor -> All Languages

Uncheck "Hide advanced members"
 
Back
Top