GUI/SensorNotifyIcon.cs
changeset 252 e62afa69214f
parent 217 d93ddd6ca0af
child 282 a2793a38aac0
     1.1 --- a/GUI/SensorNotifyIcon.cs	Thu Jan 27 22:29:43 2011 +0000
     1.2 +++ b/GUI/SensorNotifyIcon.cs	Sun Jan 30 23:45:26 2011 +0000
     1.3 @@ -112,7 +112,22 @@
     1.4          sensorSystemTray.SendHideShowCommand();
     1.5        };
     1.6  
     1.7 -      this.bitmap = new Bitmap(16, 16, PixelFormat.Format32bppArgb);
     1.8 +      // get the default dpi to create an icon with the correct size
     1.9 +      float dpiX, dpiY;
    1.10 +      using (Bitmap b = new Bitmap(1, 1, PixelFormat.Format32bppArgb)) {
    1.11 +        dpiX = b.HorizontalResolution;
    1.12 +        dpiY = b.VerticalResolution;
    1.13 +      }
    1.14 +
    1.15 +      // adjust the size of the icon to current dpi (default is 16x16 at 96 dpi) 
    1.16 +      int width = (int)Math.Round(16 * dpiX / 96);
    1.17 +      int height = (int)Math.Round(16 * dpiY / 96);
    1.18 +
    1.19 +      // make sure it does never get smaller than 16x16
    1.20 +      width = width < 16 ? 16: width;
    1.21 +      height = height < 16 ? 16: height;
    1.22 +
    1.23 +      this.bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb);      
    1.24        this.graphics = Graphics.FromImage(this.bitmap);
    1.25  
    1.26        if (Environment.OSVersion.Version.Major > 5) {
    1.27 @@ -211,7 +226,8 @@
    1.28          bytes[i + 3] = (byte)(0.3 * red + 0.59 * green + 0.11 * blue);
    1.29        }
    1.30  
    1.31 -      return IconFactory.Create(bytes, 16, 16, PixelFormat.Format32bppArgb);
    1.32 +      return IconFactory.Create(bytes, bitmap.Width, bitmap.Height, 
    1.33 +        PixelFormat.Format32bppArgb);
    1.34      }
    1.35  
    1.36      private Icon CreatePercentageIcon() {      
    1.37 @@ -220,10 +236,10 @@
    1.38        } catch (ArgumentException) {
    1.39          graphics.Clear(Color.Black);
    1.40        }
    1.41 -      graphics.FillRectangle(darkBrush, 0.5f, -0.5f, 14, 16);
    1.42 +      graphics.FillRectangle(darkBrush, 0.5f, -0.5f, bitmap.Width - 2, bitmap.Height);
    1.43        float y = 0.16f * (100 - sensor.Value.Value);
    1.44 -      graphics.FillRectangle(brush, 0.5f, -0.5f + y, 14, 16 - y);
    1.45 -      graphics.DrawRectangle(pen, 1, 0, 13, 15);
    1.46 +      graphics.FillRectangle(brush, 0.5f, -0.5f + y, bitmap.Width - 2, bitmap.Height - y);
    1.47 +      graphics.DrawRectangle(pen, 1, 0, bitmap.Width - 3, bitmap.Height - 1);
    1.48  
    1.49        BitmapData data = bitmap.LockBits(
    1.50          new Rectangle(0, 0, bitmap.Width, bitmap.Height),
    1.51 @@ -232,7 +248,8 @@
    1.52        Marshal.Copy(data.Scan0, bytes, 0, bytes.Length);
    1.53        bitmap.UnlockBits(data);
    1.54  
    1.55 -      return IconFactory.Create(bytes, 16, 16, PixelFormat.Format32bppArgb);
    1.56 +      return IconFactory.Create(bytes, bitmap.Width, bitmap.Height, 
    1.57 +        PixelFormat.Format32bppArgb);
    1.58      }
    1.59  
    1.60      public void Update() {