Hi,
I need to change the notifyicon in a countdown. after about 3000-5000 times
there is an error.
Here is all the code. what is wrong
please help
the code needs only an notifyicon and an imagelist the timer is for changing
the icon
Jan
'start code---------------------------------
Public Class Form1
Inherits System.Windows. Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeCompo nent()
'Add any initialization after the InitializeCompo nent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents ImageList1 As System.Windows. Forms.ImageList
Friend WithEvents NotifyIcon1 As System.Windows. Forms.NotifyIco n
Friend WithEvents Timer1 As System.Windows. Forms.Timer
<System.Diagnos tics.DebuggerSt epThrough()Priv ate Sub InitializeCompo nent()
Me.components = New System.Componen tModel.Containe r
Me.ImageList1 = New System.Windows. Forms.ImageList (Me.components)
Me.NotifyIcon1 = New System.Windows. Forms.NotifyIco n(Me.components )
Me.Timer1 = New System.Windows. Forms.Timer(Me. components)
'
'ImageList1
'
Me.ImageList1.I mageSize = New System.Drawing. Size(16, 16)
Me.ImageList1.T ransparentColor = System.Drawing. Color.Transpare nt
'
'NotifyIcon1
'
Me.NotifyIcon1. Text = "NotifyIcon 1"
Me.NotifyIcon1. Visible = True
'
'Timer1
'
Me.Timer1.Enabl ed = True
Me.Timer1.Inter val = 5
'
'Form1
'
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.ClientSize = New System.Drawing. Size(292, 273)
Me.Name = "Form1"
Me.ShowInTaskba r = False
Me.Text = "Form1"
End Sub
#End Region
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
sBuild_100_Icon s()
End Sub
Sub sBuild_100_Icon s()
Dim rect As Rectangle = New Rectangle(0, 0, 32, 32)
Dim displayGraphics As Graphics = Me.CreateGraphi cs()
Dim img As Image = New Bitmap(rect.Wid th, rect.Height, displayGraphics )
Dim imageGraphics As Graphics = Graphics.FromIm age(img)
Dim bcolor As Brush = New
SolidBrush(Colo r.FromKnownColo r(KnownColor.Co ntrol))
Dim cColor As Color = Color.Red
Dim fnt As New Font(Me.Font.Na me, 16, FontStyle.Bold)
For X As Byte = 0 To 99
imageGraphics.F illRectangle(bc olor, rect)
imageGraphics.D rawString(Forma t(X, "00"), fnt, New SolidBrush(cCol or), 0, _
(rect.Height - imageGraphics.M easureString(Fo rmat(X, "00"), fnt).Height) /
2)
Dim mybitmap As Bitmap = img
Dim hIcon As IntPtr = mybitmap.GetHic on
ImageList1.Imag es.Add(Icon.Fro mHandle(hIcon))
Next
End Sub
Private Sub Timer1_Tick(ByV al sender As System.Object, ByVal e As
System.EventArg s) Handles Timer1.Tick
Static Teller As Int64
Try
Teller += 1
Catch ex As Exception
Teller = 0
End Try
Dim mybitmap As Bitmap = ImageList1.Imag es(Teller Mod 100) 'I have tryed
many mod values
'te next line gives an error by the 3000-5000° times
Dim hIcon As IntPtr = mybitmap.GetHic on
NotifyIcon1.Ico n = Icon.FromHandle (hIcon)
Dim sw As New System.IO.Strea mWriter("teller .txt", True)
sw.WriteLine(Te ller)
sw.Close()
End Sub
End Class
I need to change the notifyicon in a countdown. after about 3000-5000 times
there is an error.
Here is all the code. what is wrong
please help
the code needs only an notifyicon and an imagelist the timer is for changing
the icon
Jan
'start code---------------------------------
Public Class Form1
Inherits System.Windows. Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeCompo nent()
'Add any initialization after the InitializeCompo nent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents ImageList1 As System.Windows. Forms.ImageList
Friend WithEvents NotifyIcon1 As System.Windows. Forms.NotifyIco n
Friend WithEvents Timer1 As System.Windows. Forms.Timer
<System.Diagnos tics.DebuggerSt epThrough()Priv ate Sub InitializeCompo nent()
Me.components = New System.Componen tModel.Containe r
Me.ImageList1 = New System.Windows. Forms.ImageList (Me.components)
Me.NotifyIcon1 = New System.Windows. Forms.NotifyIco n(Me.components )
Me.Timer1 = New System.Windows. Forms.Timer(Me. components)
'
'ImageList1
'
Me.ImageList1.I mageSize = New System.Drawing. Size(16, 16)
Me.ImageList1.T ransparentColor = System.Drawing. Color.Transpare nt
'
'NotifyIcon1
'
Me.NotifyIcon1. Text = "NotifyIcon 1"
Me.NotifyIcon1. Visible = True
'
'Timer1
'
Me.Timer1.Enabl ed = True
Me.Timer1.Inter val = 5
'
'Form1
'
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.ClientSize = New System.Drawing. Size(292, 273)
Me.Name = "Form1"
Me.ShowInTaskba r = False
Me.Text = "Form1"
End Sub
#End Region
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
sBuild_100_Icon s()
End Sub
Sub sBuild_100_Icon s()
Dim rect As Rectangle = New Rectangle(0, 0, 32, 32)
Dim displayGraphics As Graphics = Me.CreateGraphi cs()
Dim img As Image = New Bitmap(rect.Wid th, rect.Height, displayGraphics )
Dim imageGraphics As Graphics = Graphics.FromIm age(img)
Dim bcolor As Brush = New
SolidBrush(Colo r.FromKnownColo r(KnownColor.Co ntrol))
Dim cColor As Color = Color.Red
Dim fnt As New Font(Me.Font.Na me, 16, FontStyle.Bold)
For X As Byte = 0 To 99
imageGraphics.F illRectangle(bc olor, rect)
imageGraphics.D rawString(Forma t(X, "00"), fnt, New SolidBrush(cCol or), 0, _
(rect.Height - imageGraphics.M easureString(Fo rmat(X, "00"), fnt).Height) /
2)
Dim mybitmap As Bitmap = img
Dim hIcon As IntPtr = mybitmap.GetHic on
ImageList1.Imag es.Add(Icon.Fro mHandle(hIcon))
Next
End Sub
Private Sub Timer1_Tick(ByV al sender As System.Object, ByVal e As
System.EventArg s) Handles Timer1.Tick
Static Teller As Int64
Try
Teller += 1
Catch ex As Exception
Teller = 0
End Try
Dim mybitmap As Bitmap = ImageList1.Imag es(Teller Mod 100) 'I have tryed
many mod values
'te next line gives an error by the 3000-5000° times
Dim hIcon As IntPtr = mybitmap.GetHic on
NotifyIcon1.Ico n = Icon.FromHandle (hIcon)
Dim sw As New System.IO.Strea mWriter("teller .txt", True)
sw.WriteLine(Te ller)
sw.Close()
End Sub
End Class
Comment