Vitaly Posted November 9, 2002 Posted November 9, 2002 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. Quote
*Gurus* Derek Stone Posted November 9, 2002 *Gurus* Posted November 9, 2002 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 Quote Posting Guidelines
Vitaly Posted November 10, 2002 Author Posted November 10, 2002 Thanks for the reply. So, in .NET if I have a picture box I need to draw a rectangle with same coordinates and get DC Handle for that? Quote
*Gurus* Derek Stone Posted November 10, 2002 *Gurus* Posted November 10, 2002 No, not at all. Those two lines are just showing you how to accomplish the same thing in .NET. Quote Posting Guidelines
Vitaly Posted November 10, 2002 Author Posted November 10, 2002 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. Quote
*Gurus* Derek Stone Posted November 10, 2002 *Gurus* Posted November 10, 2002 Dim g As Graphics g = PictureBox1.CreateGraphics() MessageBox.Show(g.GetHdc.ToString(), Application.ProductName) Quote Posting Guidelines
Vitaly Posted November 10, 2002 Author Posted November 10, 2002 (edited) That's it. Thank you. Edited November 10, 2002 by Vitaly Quote
Vitaly Posted November 11, 2002 Author Posted November 11, 2002 Interestingly, gethdc and releasehdc are misisng from IntelliSense method list, but you can still see them in object browser. Quote
*Gurus* divil Posted November 12, 2002 *Gurus* Posted November 12, 2002 Tools -> Options -> Text Editor -> All Languages Uncheck "Hide advanced members" Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Recommended Posts