How can I change the icon of a Windows Form?

0

The window is open with 2 different buttons and shows different controls, depending on the button with which it was opened, but I do not know how to change the icon depending on the button with which it was instantiated.

The Icon property works perfect but only when the icon is unique to the Form; add an icon in location Properties.Resources but it does not work, it does not throw an exception and it does not work for me if I use a relative path where the .ico icon I want to use is found.

    
asked by Alec Raya 17.09.2016 в 18:38
source

1 answer

2

On each button you would have to add the following line:

this.Icon = WindowsFormsApplication1.Properties.Resources.Hopstarter_Rounded_Square_Microsoft_Excel;
This.Icon = tuAplicacion.Propiedades.Recursos.ElNombreDelIcono;

Make sure you have first inserted the icon in the program resources by accessing proyecto/propiedades (ultima opcion)/ and clicking on the resources section. Adding the images is very easy, just drag the icons of your computer to the resource window.

    
answered by 17.09.2016 в 19:38