How do I extract a Bitmap from an icon of a specific size

Icon icoClose; // Initialize this icoClose from the resource (for example). Code omitted. … … … // Now create a new icon off this base icon with the required size (18 X 18) in this case. Icon icoClose18By18 = new Icon(icoClose, 18, 18); // Create a bitmap off this icon. Bitmap bmpClose = icoClose.ToBitmap();

How to access a winapi that has a LPTSTR and maxlen param

[DllImport(‘user32.dll’, CharSet=CharSet.Auto, CallingConvention=CallingConvention.Winapi)] public static extern int GetMenuString(IntPtr hMenu, uint uIDItem, [MarshalAs(UnmanagedType.LPTStr)]string lpString,int maxCount,uint uFlag); //Usage: String caption = new String(’t’, 30);//using a dummy char ‘t’ here. int len = GetMenuString(hsysmenu, commandID, caption, 30, 0));

Why am I getting duplicate trace messages for my trace statements

This is possible if the same listener was added more than once to the Listeners list in Trace. This is possible even if an assembly that you linked do makes an additional entry for the same listener. Perform a check like this before adding a listener. if(Trace.Listeners.Count == 0) { Trace.Listeners.Add(new TextWriterTraceListener(Console.Out)); Trace.AutoFlush = true; Trace.Indent(); }

How to convert a Cursor class to a .cur file

protected void WriteCursorToFile(Cursor cursor, string fileName) { byte[] blob = TypeDescriptor.GetConverter(typeof(System.Windows.Forms.Cursor)).ConvertTo(cursor, typeof(byte[])) as byte[]; if(blob != null) { FileStream fileStream = new FileStream(fileName, FileMode.Create); fileStream.Write(blob, 0, blob.Length); fileStream.Flush(); fileStream.Close(); } else MessageBox.Show(‘Unable to convert Cursor to byte[]’); }