0

I am trying to change button image. Image which I want after button click event is given full access. Code given below is on buttonclick event.

Image i1 = Image.FromFile(@"‪E:\TEMP\BeautyParlour\BeautyParlour\Resources\Done.png");
button6.Image = null;
button6.Image = i1;

After running application when I click on button it gives me following error:

The given path's format is not supported.

With the exception as:

NotSupportedException was unhandled

  • What did you try? Maybe [this](https://stackoverflow.com/a/7348799/11867443) could help you... – aziui Feb 28 '20 at 15:00
  • Add the image to the project resources and then you can directly assign the image. – John Alexiou Feb 28 '20 at 15:51
  • 1
    If you must use a file path you should check that the app can see it. This error comes from either the file not being there or no permissions from what I can tell. Invisible characters in the path can also cause it. – Mike Cheel Feb 28 '20 at 16:10
  • Copy/pasting the path from the Explorer address bar [might get you more](https://stackoverflow.com/a/24856821/what-is-causing-notsupportedexception-the-given-paths-format-is-not-supported) than you think. You never want to do this anyway, odds that the user of your program has an e:\temp directory are too low. – Hans Passant Feb 28 '20 at 16:28
  • @aziui I visited that link already but its little bit complex to understand considering i just want to import one image but thanks :) – Atharva Kale Feb 29 '20 at 18:40
  • @MikeCheel I do gave full control of image as i stated it in my briefing of problem and for invisible spaces I copied the path from **properties / security TAB** – Atharva Kale Feb 29 '20 at 18:43
  • @HansPassant I totally agree with you considering I must group all necessary resources in project cause odds are 100% no :) – Atharva Kale Feb 29 '20 at 18:45

1 Answers1

0

I suggest adding the images you are using to the project resources. For example below I have added two images Add.png and Ok.png to my project

pic1

The to use the image, just assign it to the button

private void button1_Click(object sender, EventArgs e)
{
    button1.Image = Properties.Resources.Ok;
}
John Alexiou
  • 28,472
  • 11
  • 77
  • 133
  • Hey thanks error is gone but still its not showing image, its just only showing me text of my button – Atharva Kale Feb 29 '20 at 18:35
  • IDK without any other information. Check the image align and text-align properties on the button and if the image shows up in the resources it should be visible on the UI also. – John Alexiou Feb 29 '20 at 19:57