Ive written some code which creates a bitmap, draws on the bitmap using GDI+ and copies it to a notification icon control (NF1).
It updates this bitmap (to draw a rotating swirly thing) in a timer loop (every 25ms).
Problem is, I seem to be losing GDI objects. As far as I can tell the only place where this could be happening is in icn = Icon.FromHandle(b.GetHicon).
Anyone any ideas how I can prevent this from happening?
(Note : The application loses about 3-4Kb per second)
!EDIT! :
Ive narrowed it down to the line "icn = Icon.FromHandle(b.GetHicon)".
It creates a new icon each time around. Im just not sure how to prevent this from happening. Anyone?
It updates this bitmap (to draw a rotating swirly thing) in a timer loop (every 25ms).
Problem is, I seem to be losing GDI objects. As far as I can tell the only place where this could be happening is in icn = Icon.FromHandle(b.GetHicon).
Anyone any ideas how I can prevent this from happening?
(Note : The application loses about 3-4Kb per second)
Code:
Dim ang As Integer = 0
Dim s As Integer = 4
Dim a As Double = 0
Dim bbrsh As SolidBrush
Dim wbrsh As SolidBrush
Dim b As Bitmap
Dim g As Graphics
Dim r As Rectangle
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
bbrsh = New SolidBrush(Color.Black)
wbrsh = New SolidBrush(Color.White)
b = New Bitmap(16, 16)
g = Graphics.FromImage(b)
r = New Rectangle(0 - s, 0 - s, b.Width - 1 + (s * 2), b.Height - 1 + (s * 2))
Me.Visible = False
End Sub
Private Sub timerTick_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timerTick.Tick
DoNotificationIcon(NF1)
a = a + 0.15
ang += 8 + Int(14 * Math.Sin(a))
If ang > 180 Then ang -= 180
If ang < 0 Then ang += 180
End Sub
Private Sub DoNotificationIcon(ByVal nf As NotifyIcon)
Dim icn As Icon
g.FillPie(bbrsh, r, 0 + ang, 90)
g.FillPie(bbrsh, r, -180 + ang, 90)
g.FillPie(wbrsh, r, 90 + ang, 90)
g.FillPie(wbrsh, r, -90 + ang, 90)
icn = Icon.FromHandle(b.GetHicon)
nf.Icon = icn
icn.Dispose()
End Sub
!EDIT! :
Ive narrowed it down to the line "icn = Icon.FromHandle(b.GetHicon)".
It creates a new icon each time around. Im just not sure how to prevent this from happening. Anyone?
Last edited by a moderator: