I am trying to create a windows forms application where I want to show some text dynamically on the system tray instead of the application icon. I used the below code to create a bit map image from the text which will be used to show in system tray. But the space is not suffiecient to show 8 to 9 characters. How to create the space for 9 characters in system tray and show that ico image created from bitmap in that system tray space.
我正在尝试创建一个Windows窗体应用程序,在该应用程序中,我希望在系统托盘上动态显示一些文本,而不是应用程序图标。我使用下面的代码从文本创建了一个位图图像,它将用于在系统托盘中显示。但空格不足以显示8到9个字符。如何在系统托盘中创建9个字符的空间,并在该系统托盘空间中显示从位图创建的ICO图像。
// Create a Bitmap and draw the text on it
Bitmap bitmap = new Bitmap(16, 16);
using (Graphics g = Graphics.FromImage(bitmap))
{
g.Clear(Color.Transparent);
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
g.DrawString(newText, new Font("Arial", 8), Brushes.Black, new PointF(0, 0));
}
// Convert the Bitmap to an Icon
Icon customIcon = Icon.FromHandle(bitmap.GetHicon());
// Set the custom Icon as the icon for the NotifyIcon
notifyIcon1.Icon = customIcon;
更多回答
优秀答案推荐
我是一名优秀的程序员,十分优秀!