tabs ↹ over ␣ ␣ ␣ spaces

by Jiří {x2} Činčura

Create icon from text

10 Jul 2005 1 mins .NET

Here’s easy function for creating icon from string. I’m using it for traybar icon and for showing some usefull information on my notebook, i.e. the battery life in minutes.

private static System.Drawing.Icon DrawIcon(string IconMessage)
{
	Icon result = null;
	try
	{
		Bitmap b = new Bitmap(16,16);
		Graphics g = Graphics.FromImage((Image)b);
		g.DrawString(IconMessage,
			new Font("Arial", 10, FontStyle.Regular, GraphicsUnit.Pixel),
			new SolidBrush(System.Drawing.Color.Black),
			0,1);
 		result = Icon.FromHandle(b.GetHicon());
 		g.Dispose();
 		b.Dispose();
	}
	catch (Exception e)
	{
		//Console.WriteLine(e.Message);
	}
	return result;
}

Profile Picture Jiří Činčura is .NET, C# and Firebird expert. He focuses on data and business layers, language constructs, parallelism, databases and performance. For almost two decades he contributes to open-source, i.e. FirebirdClient. He works as a senior software engineer for Microsoft. Frequent speaker and blogger at www.tabsoverspaces.com.