How do I get a snapshot of my desktop

Here is some code that will do it. [C#] internal class NativeMethods { [DllImport(‘user32.dll’)] public extern static IntPtr GetDesktopWindow(); [System.Runtime.InteropServices.DllImport(‘user32.dll’)] public static extern IntPtr GetWindowDC(IntPtr hwnd); [System.Runtime.InteropServices.DllImport(‘gdi32.dll’)] public static extern UInt64 BitBlt (IntPtr hDestDC, int x, int y, int nWidth, int nHeight, IntPtr hSrcDC, int xSrc, int ySrc, System.Int32 dwRop); } // Save the screen capture into a jpg public void SaveScreen() { Image myImage = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); Graphics gr1 = Graphics.FromImage(myImage); IntPtr dc1 = gr1.GetHdc(); IntPtr dc2 = NativeMethods.GetWindowDC(NativeMethods.GetDesktopWindow()); NativeMethods.BitBlt(dc1, 0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, dc2, 0, 0, 13369376); gr1.ReleaseHdc(dc1); myImage.Save(‘screenshot.jpg’, ImageFormat.Jpeg); } [VB.Net] Friend Class NativeMethods _ Public Shared Function GetDesktopWindow() As IntPtr End Function _ Public Shared Function GetWindowDC(ByVal hwnd As IntPtr) As IntPtr End Function _ Public Shared Function BitBlt(ByVal hDestDC As IntPtr, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hSrcDC As IntPtr, ByVal xSrc As Integer, ByVal ySrc As Integer, ByVal dwRop As System.Int32) As UInt64 End Function End Class ’NativeMethods ’Save the screen capture into a jpg Private Sub SaveScreen() Dim myImage = New Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height) Dim gr1 As Graphics = Graphics.FromImage(myImage) Dim dc1 As IntPtr = gr1.GetHdc() Dim dc2 As IntPtr = NativeMethods.GetWindowDC(NativeMethods.GetDesktopWindow()) NativeMethods.BitBlt(dc1, 0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, dc2, 0, 0, 13369376) gr1.ReleaseHdc(dc1) myImage.Save(‘screenshot.jpg’, ImageFormat.Jpeg) End Sub ’SaveScreen

How do I prevent the context menu from showing up on certain keyboard keys (like Keys.Apps)?

Override WndProc in your Control and do the following. You should then listen to keyup and show the context menu yourself. [C#] protected override void WndProc(ref Message m) { if(m.Msg == 0x7b /*WM_CONTEXTMENU*/ ) { return; } if(m.Msg == 0x101 /*WM_KEYUP*/) { Keys keys = (Keys)m.WParam.ToInt32(); // Prevent this key from being processed. if(keys == Keys.Apps) return; } base.WndProc(ref m); } [VB.Net] Protected Overrides Sub WndProc(ByRef m As Message) If m.Msg = 0x7b Then ’WM_CONTEXTMENU Return End If If m.Msg = 0x101 Then ’WM_KEYUP Dim keys As Keys = CType(m.WParam.ToInt32(), Keys) ’ Prevent this key from being processed. If keys = Keys.Apps Then Return End If End If MyBase.WndProc( m) End Sub

How to debug your design time code (like designers, typeconverters, etc.)

You need to use a second instance of VS.NET to debug the one that’s running the code. Put your control on a from in VS.NET Start a 2nd Vs.Net Choose the Debug menu >> Processes … Double click ‘devenv.exe’ and choose ‘Common Language Runtime’ as the types of debugging Open your code file, set your breakpoint, and you’re debugging. Posted by Shawn Burke of MSFT in microsoft.public.dotnet.framework.windowsforms.