J
JR
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.
InitializeComponent()
'Add any initialization after the InitializeComponent() 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.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'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.NotifyIcon
Friend WithEvents Timer1 As System.Windows.Forms.Timer
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Me.ImageList1 = New System.Windows.Forms.ImageList(Me.components)
Me.NotifyIcon1 = New System.Windows.Forms.NotifyIcon(Me.components)
Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
'
'ImageList1
'
Me.ImageList1.ImageSize = New System.Drawing.Size(16, 16)
Me.ImageList1.TransparentColor = System.Drawing.Color.Transparent
'
'NotifyIcon1
'
Me.NotifyIcon1.Text = "NotifyIcon1"
Me.NotifyIcon1.Visible = True
'
'Timer1
'
Me.Timer1.Enabled = True
Me.Timer1.Interval = 5
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Name = "Form1"
Me.ShowInTaskbar = False
Me.Text = "Form1"
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
sBuild_100_Icons()
End Sub
Sub sBuild_100_Icons()
Dim rect As Rectangle = New Rectangle(0, 0, 32, 32)
Dim displayGraphics As Graphics = Me.CreateGraphics()
Dim img As Image = New Bitmap(rect.Width, rect.Height, displayGraphics)
Dim imageGraphics As Graphics = Graphics.FromImage(img)
Dim bcolor As Brush = New
SolidBrush(Color.FromKnownColor(KnownColor.Control))
Dim cColor As Color = Color.Red
Dim fnt As New Font(Me.Font.Name, 16, FontStyle.Bold)
For X As Byte = 0 To 99
imageGraphics.FillRectangle(bcolor, rect)
imageGraphics.DrawString(Format(X, "00"), fnt, New SolidBrush(cColor), 0, _
(rect.Height - imageGraphics.MeasureString(Format(X, "00"), fnt).Height) /
2)
Dim mybitmap As Bitmap = img
Dim hIcon As IntPtr = mybitmap.GetHicon
ImageList1.Images.Add(Icon.FromHandle(hIcon))
Next
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
Static Teller As Int64
Try
Teller += 1
Catch ex As Exception
Teller = 0
End Try
Dim mybitmap As Bitmap = ImageList1.Images(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.GetHicon
NotifyIcon1.Icon = Icon.FromHandle(hIcon)
Dim sw As New System.IO.StreamWriter("teller.txt", True)
sw.WriteLine(Teller)
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.
InitializeComponent()
'Add any initialization after the InitializeComponent() 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.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'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.NotifyIcon
Friend WithEvents Timer1 As System.Windows.Forms.Timer
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Me.ImageList1 = New System.Windows.Forms.ImageList(Me.components)
Me.NotifyIcon1 = New System.Windows.Forms.NotifyIcon(Me.components)
Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
'
'ImageList1
'
Me.ImageList1.ImageSize = New System.Drawing.Size(16, 16)
Me.ImageList1.TransparentColor = System.Drawing.Color.Transparent
'
'NotifyIcon1
'
Me.NotifyIcon1.Text = "NotifyIcon1"
Me.NotifyIcon1.Visible = True
'
'Timer1
'
Me.Timer1.Enabled = True
Me.Timer1.Interval = 5
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Name = "Form1"
Me.ShowInTaskbar = False
Me.Text = "Form1"
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
sBuild_100_Icons()
End Sub
Sub sBuild_100_Icons()
Dim rect As Rectangle = New Rectangle(0, 0, 32, 32)
Dim displayGraphics As Graphics = Me.CreateGraphics()
Dim img As Image = New Bitmap(rect.Width, rect.Height, displayGraphics)
Dim imageGraphics As Graphics = Graphics.FromImage(img)
Dim bcolor As Brush = New
SolidBrush(Color.FromKnownColor(KnownColor.Control))
Dim cColor As Color = Color.Red
Dim fnt As New Font(Me.Font.Name, 16, FontStyle.Bold)
For X As Byte = 0 To 99
imageGraphics.FillRectangle(bcolor, rect)
imageGraphics.DrawString(Format(X, "00"), fnt, New SolidBrush(cColor), 0, _
(rect.Height - imageGraphics.MeasureString(Format(X, "00"), fnt).Height) /
2)
Dim mybitmap As Bitmap = img
Dim hIcon As IntPtr = mybitmap.GetHicon
ImageList1.Images.Add(Icon.FromHandle(hIcon))
Next
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
Static Teller As Int64
Try
Teller += 1
Catch ex As Exception
Teller = 0
End Try
Dim mybitmap As Bitmap = ImageList1.Images(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.GetHicon
NotifyIcon1.Icon = Icon.FromHandle(hIcon)
Dim sw As New System.IO.StreamWriter("teller.txt", True)
sw.WriteLine(Teller)
sw.Close()
End Sub
End Class