does any one knwo how to get this value in Vb.Net?
and is this value large for an object in vb6?
Printable View
does any one knwo how to get this value in Vb.Net?
and is this value large for an object in vb6?
Form1.DefInstance.Handle.ToInt32
Yes since you are using ToInt32
Shoot. My bad. It only works when VB6 Forms have been upgraded to VB.NET and have contained code on hDC's.
Try doing this:
Dim Form as New Control
and use Form.Handle.Int32 for whereever hDC was needed.
I was wrong. Handle is actually like VB6's hWnd. Sorry, but at least I tried.
AH HA, here it is:
Dim Form as New Form1
Dim hDC as Long
hdc = Form1.CreateGraphics.GetHdc.ToInt32
GetHdc is a hidden member and won't appear in the list after typing CreateGraphics.
Thanks Jacob Roman from 8 years ago.
hdc = Form1.CreateGraphics.GetHdc.ToInt32 Its exactely what I needed to get the handler of my form..
Just an FYI, Verzulsan from 1 month ago, there is no need to append ".ToInt32" to that since it is already an IntPtr. Also, be sure to use ".ReleaseHdc" afterwards, like so:
This will pass ownership of the device context back to the original owner, allowing the graphics device to continue as it normally would.vb Code:
Dim g As Graphics = Form1.CreateGraphics() Dim hdc As IntPtr = g.GetHdc() ' Borrows control over the device context ' ' Use the device context here... ' g.ReleaseHdc()' Gives control back to owner
A more correct version:
Code:Imports System.Runtime.InteropServices
Public Class Form1
Dim Grp As Graphics
Dim hDC As HandleRef
Private Sub Form1_HandleCreated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.HandleCreated
Grp = Me.CreateGraphics
hDC = New HandleRef(Grp, Grp.GetHdc)
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
DirectCast(hDC.Wrapper, Graphics).ReleaseHdc()
Grp.Dispose()
End Sub
End Class