S
Smokey Grindel
I have an app that runs in the system tray. It takes an icon from the
programs resources then draws two rectangles on it and numbers... the wierd
thing is its crashing... here is the exception I am getting
System.ArgumentException: Parameter is not valid.
at System.Drawing.Biutmap..ctor(Int32 width, Int32 height, PixelFormat
format)
at System.Drawing.Icon.ToBitmap()
at System.Windows.Forms.ThreadExceptionDialog..ctor(Exception t)
at
System.Windows.Forms.Application.ThreadContext.OnThreadException(Exception
t)
....
here is the code where it is crashing... anyone catch anything wrong? I know
its a mess its just "proof of concept" type code writen quickly
this crash doesnt always happen... it will run all day fine but at night it
just seems to crash...
Thanks!
Using fntLarge As New Font("Arial", 12, FontStyle.Regular,
GraphicsUnit.Pixel), fntSmall As New Font("Arial", 8, FontStyle.Regular,
GraphicsUnit.Pixel)
' draw icon numbers
Using bmp As Bitmap = New Drawing.Icon(My.Resources.star_yellow, New
Size(16, 16)).ToBitmap
Using g As Graphics = Graphics.FromImage(bmp)
' do ind count first
g.SmoothingMode = Drawing2D.SmoothingMode.None
g.TextRenderingHint =
Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit
If IndCount > 0 Then
If IndCount > 9 Then
Dim rect As New RectangleF(New PointF(9, 5), New Size(7, 11))
Using sf As New StringFormat
sf.Alignment = StringAlignment.Center
sf.LineAlignment = StringAlignment.Center
sf.FormatFlags = StringFormatFlags.DirectionVertical
g.FillRectangle(Brushes.Blue, rect)
g.DrawString(IndCount.ToString, fntSmall, Brushes.White, New RectangleF(6,
2, 9, 16), sf)
End Using
Else
g.FillRectangle(Brushes.Blue, New RectangleF(New PointF(9, 5), New Size(7,
11)))
g.DrawString(IndCount.ToString.Trim, fntLarge, Brushes.White, 7, 3)
End If
End If
' do mc count second
If MCCount > 0 Then
If MCCount > 9 Then
Dim rect As New RectangleF(New PointF(0, 5), New Size(7, 15))
Using sf As New StringFormat
sf.Alignment = StringAlignment.Center
sf.LineAlignment = StringAlignment.Center
sf.FormatFlags = StringFormatFlags.DirectionVertical
g.FillRectangle(Brushes.DarkGreen, rect)
g.DrawString(MCCount.ToString, fntSmall, Brushes.White, New RectangleF(-2,
2, 9, 16), sf)
End Using
Else
g.FillRectangle(Brushes.DarkGreen, New RectangleF(New PointF(0, 5), New
Size(7, 15)))
g.DrawString(MCCount.ToString, fntLarge, Brushes.White, -1, 3)
End If
End If
ntfIcon.Icon = Icon.FromHandle(bmp.GetHicon)
End Using
End Using
End Using
programs resources then draws two rectangles on it and numbers... the wierd
thing is its crashing... here is the exception I am getting
System.ArgumentException: Parameter is not valid.
at System.Drawing.Biutmap..ctor(Int32 width, Int32 height, PixelFormat
format)
at System.Drawing.Icon.ToBitmap()
at System.Windows.Forms.ThreadExceptionDialog..ctor(Exception t)
at
System.Windows.Forms.Application.ThreadContext.OnThreadException(Exception
t)
....
here is the code where it is crashing... anyone catch anything wrong? I know
its a mess its just "proof of concept" type code writen quickly
this crash doesnt always happen... it will run all day fine but at night it
just seems to crash...
Thanks!
Using fntLarge As New Font("Arial", 12, FontStyle.Regular,
GraphicsUnit.Pixel), fntSmall As New Font("Arial", 8, FontStyle.Regular,
GraphicsUnit.Pixel)
' draw icon numbers
Using bmp As Bitmap = New Drawing.Icon(My.Resources.star_yellow, New
Size(16, 16)).ToBitmap
Using g As Graphics = Graphics.FromImage(bmp)
' do ind count first
g.SmoothingMode = Drawing2D.SmoothingMode.None
g.TextRenderingHint =
Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit
If IndCount > 0 Then
If IndCount > 9 Then
Dim rect As New RectangleF(New PointF(9, 5), New Size(7, 11))
Using sf As New StringFormat
sf.Alignment = StringAlignment.Center
sf.LineAlignment = StringAlignment.Center
sf.FormatFlags = StringFormatFlags.DirectionVertical
g.FillRectangle(Brushes.Blue, rect)
g.DrawString(IndCount.ToString, fntSmall, Brushes.White, New RectangleF(6,
2, 9, 16), sf)
End Using
Else
g.FillRectangle(Brushes.Blue, New RectangleF(New PointF(9, 5), New Size(7,
11)))
g.DrawString(IndCount.ToString.Trim, fntLarge, Brushes.White, 7, 3)
End If
End If
' do mc count second
If MCCount > 0 Then
If MCCount > 9 Then
Dim rect As New RectangleF(New PointF(0, 5), New Size(7, 15))
Using sf As New StringFormat
sf.Alignment = StringAlignment.Center
sf.LineAlignment = StringAlignment.Center
sf.FormatFlags = StringFormatFlags.DirectionVertical
g.FillRectangle(Brushes.DarkGreen, rect)
g.DrawString(MCCount.ToString, fntSmall, Brushes.White, New RectangleF(-2,
2, 9, 16), sf)
End Using
Else
g.FillRectangle(Brushes.DarkGreen, New RectangleF(New PointF(0, 5), New
Size(7, 15)))
g.DrawString(MCCount.ToString, fntLarge, Brushes.White, -1, 3)
End If
End If
ntfIcon.Icon = Icon.FromHandle(bmp.GetHicon)
End Using
End Using
End Using