How do you clear the contents of a list box?
You have to access the Items of the ListBox using the Items property and clear (or otherwise operate on the items) these. this.lb1.Items.Clear();
When using the ContextMenu on multiple Controls, how do I know on which Control the right click was performed?
The ContextMenu.SourceControl property will specify the latest Control on which the context menu was shown.
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
What is the best method to override in custom Controls to perform custom initialization during runtime?
When custom initialization is to be done during runtime on certain Controls, the best way is to implement the ISupportInitialize interface in that Control. Then the BeginInit method will be called as soon as the Control gets created and EndInit will be called after the design-time initialization of that control.
Are there any events that get fired when the user scrolls?
You could override WndProc and listen for (0x114 WM_HSCROLL) and (0x115 WM_VSCROLL) messages (m.Msg will be set to the above values). These messages should be sent when the user scrolls.