@@ -91,41 +91,21 @@ public SensorNotifyIcon(SystemTray sensorSystemTray, ISensor sensor, PersistentS
9191 }
9292
9393 // adjust the size of the icon to current dpi (default is 16x16 at 96 dpi)
94- int width = ( int ) Math . Round ( 16 * dpiX / 96 ) ;
95- int height = ( int ) Math . Round ( 16 * dpiY / 96 ) ;
96-
97- // make sure it does never get smaller than 16x16
98- width = width < 16 ? 16 : width ;
99- height = height < 16 ? 16 : height ;
94+ var width = Math . Max ( 16 , ( int ) Math . Round ( 16 * dpiX / 96 ) ) ;
95+ var height = Math . Max ( 16 , ( int ) Math . Round ( 16 * dpiY / 96 ) ) ;
10096
10197 // adjust the font size to the icon size
102- FontFamily family = SystemFonts . MessageBoxFont . FontFamily ;
103- float baseSize ;
104- if ( IsFontInstalled ( "Calibri" , 15 ) )
105- {
106- family = new FontFamily ( "Calibri" ) ;
107- baseSize = 15 ;
108- }
109- else if ( IsFontInstalled ( "Segoe UI" , 15 ) )
110- {
111- family = new FontFamily ( "Segoe UI" ) ;
112- baseSize = 15 ;
113- }
114- else
115- {
116- family = SystemFonts . MessageBoxFont . FontFamily ;
117- baseSize = 14 ;
118- }
119-
120- _font = new Font ( family , baseSize * width / 16.0f , GraphicsUnit . Pixel ) ;
121- _smallFont = new Font ( family , 0.7f * baseSize * width / 16.0f , GraphicsUnit . Pixel ) ;
98+ _font = new Font ( "Arial" , width == 16 ? 9.0F : 8.0F * dpiX / 96 ) ;
99+ _smallFont = new Font ( "Arial" , width == 16 ? 7.0F : 6.0F * dpiX / 96 ) ;
122100
123101 _bitmap = new Bitmap ( width , height , PixelFormat . Format32bppArgb ) ;
124102 _graphics = Graphics . FromImage ( _bitmap ) ;
125103 if ( Environment . OSVersion . Version . Major > 5 )
126104 {
127- _graphics . TextRenderingHint = TextRenderingHint . ClearTypeGridFit ;
128- _graphics . SmoothingMode = SmoothingMode . HighQuality ;
105+ _graphics . TextRenderingHint = TextRenderingHint . AntiAliasGridFit ;
106+ _graphics . SmoothingMode = SmoothingMode . AntiAlias ;
107+ _graphics . InterpolationMode = InterpolationMode . HighQualityBicubic ;
108+ _graphics . PixelOffsetMode = PixelOffsetMode . HighQuality ;
129109 }
130110 }
131111
@@ -275,21 +255,19 @@ private Icon CreateTransparentIcon()
275255 {
276256 var bigPart = text . Substring ( 0 , 1 ) ;
277257 var smallPart = text . Substring ( 1 ) ;
278- var bigSize = TextRenderer . MeasureText ( bigPart , _font ) ;
279- var smallSize = TextRenderer . MeasureText ( smallPart , _smallFont ) ;
280- TextRenderer . DrawText ( _graphics , bigPart , _font , new Point ( - 4 , ( _bitmap . Height - bigSize . Height ) / 2 ) , _color , defaultBackColor ) ;
281- TextRenderer . DrawText ( _graphics , smallPart , _smallFont , new Point ( 4 * ( _bitmap . Width / 8 - 1 ) , _bitmap . Height - smallSize . Height ) , _color , defaultBackColor ) ;
258+ TextRenderer . DrawText ( _graphics , bigPart , _font , new Point ( - _bitmap . Width / 4 , _bitmap . Height / 2 ) , _color , defaultBackColor , TextFormatFlags . VerticalCenter ) ;
259+ TextRenderer . DrawText ( _graphics , smallPart , _smallFont , new Point ( _bitmap . Width / 4 , _bitmap . Height ) , _color , defaultBackColor , TextFormatFlags . Bottom ) ;
282260 }
283261 else
284262 {
285263 var size = TextRenderer . MeasureText ( text , _smallFont ) ;
286- TextRenderer . DrawText ( _graphics , text , _smallFont , new Point ( ( _bitmap . Width - size . Width ) / 2 , ( _bitmap . Height - size . Height ) / 2 ) , _color , defaultBackColor ) ;
264+ TextRenderer . DrawText ( _graphics , text , _smallFont , new Point ( ( _bitmap . Width - size . Width ) / 2 , _bitmap . Height / 2 ) , _color , defaultBackColor , TextFormatFlags . VerticalCenter ) ;
287265 }
288266 }
289267 else
290268 {
291269 var size = TextRenderer . MeasureText ( text , _font ) ;
292- TextRenderer . DrawText ( _graphics , text , _font , new Point ( ( _bitmap . Width - size . Width ) / 2 , ( _bitmap . Height - size . Height ) / 2 ) , _color , defaultBackColor ) ;
270+ TextRenderer . DrawText ( _graphics , text , _font , new Point ( ( _bitmap . Width - size . Width ) / 2 , _bitmap . Height / 2 ) , _color , defaultBackColor , TextFormatFlags . VerticalCenter ) ;
293271 }
294272
295273 BitmapData data = _bitmap . LockBits (
0 commit comments