|
-
Nov 28th, 2004, 09:53 PM
#1
Thread Starter
New Member
hDC in VB.Net
does any one knwo how to get this value in Vb.Net?
and is this value large for an object in vb6?
-
Dec 3rd, 2004, 03:11 PM
#2
Re: hDC in VB.Net
Form1.DefInstance.Handle.ToInt32
Yes since you are using ToInt32
-
Dec 3rd, 2004, 03:42 PM
#3
Re: hDC in VB.Net
Shoot. My bad. It only works when VB6 Forms have been upgraded to VB.NET and have contained code on hDC's.
-
Dec 3rd, 2004, 04:04 PM
#4
Re: hDC in VB.Net
Try doing this:
Dim Form as New Control
and use Form.Handle.Int32 for whereever hDC was needed.
-
Dec 4th, 2004, 03:57 PM
#5
Re: hDC in VB.Net
I was wrong. Handle is actually like VB6's hWnd. Sorry, but at least I tried.
-
Dec 5th, 2004, 07:28 PM
#6
Re: hDC in VB.Net
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.
-
Feb 15th, 2012, 12:39 PM
#7
New Member
Re: hDC in VB.Net
Thanks Jacob Roman from 8 years ago.
hdc = Form1.CreateGraphics.GetHdc.ToInt32 Its exactely what I needed to get the handler of my form..
-
Mar 6th, 2012, 10:41 AM
#8
New Member
Re: hDC in VB.Net
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:
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
This will pass ownership of the device context back to the original owner, allowing the graphics device to continue as it normally would.
-
Mar 7th, 2012, 01:24 AM
#9
Re: hDC in VB.Net
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|