I want to change a Form's Icon at runtime.
see 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 running this program, the private bytes counter continually
increase.
How can I dispose the resource ?
What is the correct  way to change a Form's icon at runtime ?

-- 
You received this message because you are subscribed to the Google
Groups "DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML
Web Services,.NET Remoting" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/dotnetdevelopment?hl=en?hl=en
or visit the group website at http://megasolutions.net

Reply via email to