PictureBox does not display image

In my C # project, I used Tools to add a PictureBox control. I set the image location to PNG location on our network, and I have the same problems as others, if the images are moved from this directory, then the image in my program will not be displayed.

I would like to embed images in EXE when it is compiled so that the images are not dependent on the actual file available on the network. I found an article that says to make my image a resource in my project. I did this, but when I try to use it, I see an error: stream is not a valid resource file.

I know that this can be achieved, but I have not yet found what I need to do.

How do I configure this? Because I'm obviously misconfigured.

+4
source share
3 answers

Step1: RightClick in the project

Step 2: Select "Properties."

Step 3. Go to the Resources tab.

Step4: Click β€œAdd a drop-down menu” as shown in the figure below.

Step 5. Select Add Existing File ...

Step6: Now select the file you want to add as a resource from the file browsing dialog box.

Step7: Select the snapshot to add and set the property to PersistenceEmbedded in .resx

then the image is embedded in your application;)

to access her

pictureBox1.Image = Properties.Resources.ImageName;
+10
source

Solution 1: you can use PictureBoxControl to display images in Windows Form.

:

PictureBox ToolBox WindowsForm.

Click :

private void Button1_Click(object sender, EventArgs e)
    {          
        pictureBox1.Image = Image.FromFile("path of imge file");
    }

2: , Resources .

:

1: RightClick Project

2: Properties.

3: Resources, .

4: Add Resource , .

5: Add Existing File...

6: , .

ScreenShot:

enter image description here

, :
. : sudhakar.

pictureBox1.Image = Properties.Resources.sudhakar;
+1

You can add your icon to the resources of your application.

  • Click the Resources tab from the properties / resources in the solution explorer. enter image description here
  • Choose Add Resource β†’ Add Existing File. enter image description here
  • Select an icon to add and save changes to resources.
  • Now you can use this icon in the PictureBox properties dialog box to select the icon enter image description here
0
source

Source: https://habr.com/ru/post/1526996/


All Articles