PC Review


Reply
Thread Tools Rate Thread

How can I dispose the resource of changed Form's Icon ?

 
 
puma delicious
Guest
Posts: n/a
 
      19th Apr 2011
I want to change a Form's icon at runtime.
here's my sample code:

public partial class Form1 : Form
{
bool changingIcon = false;
Icon blankIcon;
Icon musicIcon;
int iconState = 0;

public Form1()
{
InitializeComponent();

timer1.Interval = 1000;

blankIcon = (Icon)Properties.Resources.blankcd.Clone();
musicIcon = (Icon)Properties.Resources.cdmusic.Clone();

}

private void button1_Click(object sender, EventArgs e)
{
if (changingIcon)
{
changingIcon = false;
timer1.Enabled = false;
}
else
{
changingIcon = true;
timer1.Enabled = true;
}
}

private void timer1_Tick(object sender, EventArgs e)
{
Icon previousIcon = this.Icon;
IntPtr hIcon = previousIcon.Handle;
previousIcon.Dispose();

if (0 == iconState)
{
this.Icon = (Icon)blankIcon.Clone();
iconState = 1;
}
else
{
this.Icon = (Icon)musicIcon.Clone();
iconState = 0;
}
}

}

But when runnning this program, the privatebytes counter continually
increase.
How can I dispose the resource of changed Form's Icon ?
What is the correct way to change a Form's icon at runtime ?
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
MDI Icon dispose error? Smokey Grindle Microsoft VB .NET 0 18th Jul 2006 02:01 PM
Proper resource deallocation through Dispose() Michael Russell Microsoft ADO .NET 3 13th Jul 2006 03:48 PM
Proper resource deallocation through Dispose() Michael Russell Microsoft Dot NET Framework 0 12th Jul 2006 04:49 PM
Form.Dispose does not invoke InputPanel.Dispose tomj@softhome.net Microsoft Dot NET Compact Framework 3 24th Jan 2006 03:28 PM
Icon changed for my new form? M Dak Microsoft Outlook Contacts 1 13th Jan 2005 10:54 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:00 PM.