[quoted text, click to view] Smokey Grindel wrote: > 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() <snip> > Using bmp As Bitmap = New Drawing.Icon(My.Resources.star_yellow, New > Size(16, 16)).ToBitmap
<snip> It seems you're not disposing the temporary Icon you create to extract the bitmap from. If you're doing this a lot of times, it could explain the crash after a long run (all other things staying the same). If you're going to recreate this icon a gazillion times during the app lifetime, I suggest you create it just once, when the app starts, and place it somewhere your code can reach (actually, you could do the same with fntSmall and fntLarge)... Otherwise use something like: Using Bmp as Bitmap Using I as New Drawing.Icon(....) Bmp = I.ToBitmap End Using '... HTH. Regards, Branco.
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
cant believe I didn't catch that... thanks! also moved the font definitions up to a private member of the class so they are only created once with the class instance instead of each time.. Hopefully this was the problem [quoted text, click to view] "Branco Medeiros" <branco.medeiros@gmail.com> wrote in message news:1174659772.437526.182130@l75g2000hse.googlegroups.com... > Smokey Grindel wrote: >> 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() > <snip> >> Using bmp As Bitmap = New Drawing.Icon(My.Resources.star_yellow, New >> Size(16, 16)).ToBitmap > <snip> > > It seems you're not disposing the temporary Icon you create to extract > the bitmap from. If you're doing this a lot of times, it could explain > the crash after a long run (all other things staying the same). > > If you're going to recreate this icon a gazillion times during the app > lifetime, I suggest you create it just once, when the app starts, and > place it somewhere your code can reach (actually, you could do the > same with fntSmall and fntLarge)... > > Otherwise use something like: > > Using Bmp as Bitmap > Using I as New Drawing.Icon(....) > Bmp = I.ToBitmap > End Using > '... > > HTH. > > Regards, > > Branco. >
Don't see what you're looking for? Try a search.
|