Why do the XP Icons when drawn using Graphics.DrawImage not draw transparently?
Note that it’s only the ImageList class that can draw an Icon with alpha channel properly. So, instead of using the Graphics.DrawImage method, first associate this icon to a ImageList and then use the ImageList.Draw method to draw the icon. Also, note that this is possible only in XP with XP Themes enabled for that application.
Why do the XP Icons that have alpha channel not draw properly when associated with controls like ListView?
Make sure that you include the manifest file that will enable XP themes support for you application. Then the icons with alpha channel will draw semi-transparently.
How do I prevent resizing of my Controls by the user, via Docking or anchoring or manual resizing during design-time?
The best place to ensure a particular height/width for you control is in the SetBoundsCore override of your Control, as follows: protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) { int prefHeight = this.GetPreferredHeight(); // Ensure that the height is atleast as big as prefHeight if(height < prefHeight) height = prefHeight; base.SetBoundsCore(x, y, width, height, specified); } Protected Overrides Sub SetBoundsCore(ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal specified As BoundsSpecified) Dim prefHeight As Integer = Me.GetPreferredHeight() ’ Ensure that the height is atleast as big as prefHeight If height < prefHeight Then height = prefHeight End If MyBase.SetBoundsCore(x, y, width, height, specified) End Sub
How do I force a Windows Form application to exit
Your main form is an object of type System.Windows.Forms.Form. Use its Close method to exit the application. If you wish to Exit from a Form’s constructor, this will not work. A workaround is to set a boolean flag that you can later check in the Form’s Load method to call Close if required. Another way is to use the Application.Exit() method.
How do I cancel a context menu programatically?
First keep track of which control is showing the ContextMenu by listening to the menu’s Popup event and querying for the SourceControl. Then when you are ready to cancel the popup, do as follows: [C#] [DllImport(‘user32.dll’, CharSet=CharSet.Auto)] extern internal static IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam); private void Timer_Tick(object sender, EventArgs e) { if(menuSourceControl != null) SendMessage(menuSourceControl.Handle, 0x001F/*WM_CANCELMODE*/, IntPtr.Zero, IntPtr.Zero); } [VB.Net] _ extern internal static IntPtr SendMessage(IntPtr hWnd, Integer msg, IntPtr wParam, IntPtr lParam) Private Sub Timer_Tick(ByVal sender As Object, ByVal e As EventArgs) If Not menuSourceControl Is Nothing Then SendMessage(menuSourceControl.Handle, 0x001F, IntPtr.Zero, IntPtr.Zero) End If End Sub