[RESOLVED] change icon, based on given path
hey everyone,
so i have this program i am workikng on, and i created a custom icon for it. i know that in visual studio i can just change the icon setting on the form to whatever icon i select and its changed. but i want to do it from within the program itself. that way if i feel like changing the icon to something different, i just write the path in the config file and it changes itself.
ideas?
here is the config key
Code:
<add key="icon" value="E:\Users\Owner\Documents\Visual Studio 2010\Projects\CS_CheckInCheckOut\CS_CheckInCheckOut\Icon.ico"/>
i tried this:
Code:
string iconpath = ConfigurationSettings.AppSettings["icon"];
public frmMain()
{
InitializeComponent();
this.KeyDown += new KeyEventHandler(frmMain_KeyDown);
this.PreviewKeyDown += new PreviewKeyDownEventHandler(frmMain_PreviewKeyDown);
textBox1.Text = "Last Name";
textBox2.Text = "First Name";
frmMain.Icon = iconpath;
}
but it gave me this:
Code:
Error 2 An object reference is required for the non-static field, method, or property 'System.Windows.Forms.Form.Icon.get' E:\Users\Owner\documents\visual studio 2010\Projects\CS_CheckInCheckOut\CS_CheckInCheckOut\Form1.cs 28 13 CS_CheckInCheckOut
i am going to search around the internet for answers, but please help me understand this.
thanks in advance,
rockking
Re: change icon, based on given path
I'm not sure it can work, but your compilation error is caused by the line frmMain.Icon = iconpath;, because from the syntaxt it seems that frmMain is a class (maybe descendant of a form) and it has not static property Icon. You have to change it to
Code:
this.Icon = new Icon(iconpath)
because you have to set an Icon to the property, not just the path.
Re: change icon, based on given path
hey
thanks for the help boudino, that worked perfectly and is great for using several icons in one project. thank you