Question

I am relatively new to programming and have started to code in C#, now. I am making a tiny program, that I want to consist of just a single *.exe file. The program is a windows form with some pictures on it, there are some default starting ones and others that need to be shown under certain conditions. Basically they are the same PictureBox(es) that I just change with PictureBox.Image = System.Drawing.Image.FromFile(@"C:\teh image.jpg");

I used the "Choose Image" option on the Picture Boxes to locate each default picture on my hard drive and have, sort of, found out that they are included in the *.exe file, beacuse if I change the folder's name (the one containing the pictures) the program runs smoothly. I want to do the same for the other pictures that I need to be shown later, I thought that maybe after I included my .image.fromfile, etc. the all-wise compilator will see it and include the other pictures, as well, but it did not. So I want to know how I can do that.

As a bonus question, there seems to be an error in my code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Heroes5_ArmyCalc
{
    public partial class Form1 : Form
    {
        int Current_Tier1_01_Gold=3333;
        int Current_Tier1_02_Gold;
        int Current_Tier2_01_Gold;
        int Current_Tier2_02_Gold;
        int Current_Tier3_01_Gold;
        int Current_Tier3_02_Gold;
        int Current_Tier4_01_Gold;
        int Current_Tier4_02_Gold;
        int Current_Tier5_01_Gold;
        int Current_Tier5_02_Gold;
        int Current_Tier6_01_Gold;
        int Current_Tier6_02_Gold;
        int Current_Tier7_01_Gold;
        int Current_Tier7_02_Gold;
        int Current_Tier1_Pop;
        int Current_Tier2_Pop;
        int Current_Tier3_Pop;
        int Current_Tier4_Pop;
        int Current_Tier5_Pop;
        int Current_Tier6_Pop;
        int Current_Tier7_Pop;
        int Haven_Tier1_01_Gold = 15;
        int Haven_Tier1_02_Gold = 25;
        int Haven_Tier2_01_Gold = 50;
        int Haven_Tier2_02_Gold = 80;
        int Haven_Tier3_01_Gold = 85;
        int Haven_Tier3_02_Gold = 130;
        int Haven_Tier4_01_Gold = 250;
        int Haven_Tier4_02_Gold = 370;
        int Haven_Tier5_01_Gold = 600;
        int Haven_Tier5_02_Gold = 850;
        int Haven_Tier6_01_Gold = 1300;
        int Haven_Tier6_02_Gold = 1700;
        int Haven_Tier7_01_Gold = 2800;
        int Haven_Tier7_02_Gold = 3500;
        int Haven_Tier1_Pop = 22;
        int Haven_Tier2_Pop = 12;
        int Haven_Tier3_Pop = 10;
        int Haven_Tier4_Pop = 5;
        int Haven_Tier5_Pop = 3;
        int Haven_Tier6_Pop = 2;
        int Haven_Tier7_Pop = 1;

        public Form1()
        {
            InitializeComponent();
            Current_Haven();
            Basics();
        }

        public void Basics()
        {
            Gold_Tier1.Text = Convert.ToString(Current_Tier1_01_Gold);
            Gold_Tier2.Text = Convert.ToString(Current_Tier2_01_Gold);
            Gold_Tier3.Text = Convert.ToString(Current_Tier3_01_Gold);
            Gold_Tier4.Text = Convert.ToString(Current_Tier4_01_Gold);
            Gold_Tier5.Text = Convert.ToString(Current_Tier5_01_Gold);
            Gold_Tier6.Text = Convert.ToString(Current_Tier6_01_Gold);
            Gold_Tier7.Text = Convert.ToString(Current_Tier7_01_Gold);
            Pop_Tier1.Text = Convert.ToString(Current_Tier1_Pop);
            Pop_Tier2.Text = Convert.ToString(Current_Tier2_Pop);
            Pop_Tier3.Text = Convert.ToString(Current_Tier3_Pop);
            Pop_Tier4.Text = Convert.ToString(Current_Tier4_Pop);
            Pop_Tier5.Text = Convert.ToString(Current_Tier5_Pop);
            Pop_Tier6.Text = Convert.ToString(Current_Tier6_Pop);
            Pop_Tier7.Text = Convert.ToString(Current_Tier7_Pop);
        }

        public void Current_Haven()
        {
            int Current_Tier1_01_Gold = Haven_Tier1_01_Gold;
            int Current_Tier1_02_Gold = Haven_Tier1_02_Gold;
            int Current_Tier2_01_Gold = Haven_Tier2_01_Gold;
            int Current_Tier2_02_Gold = Haven_Tier2_02_Gold;
            int Current_Tier3_01_Gold = Haven_Tier3_01_Gold;
            int Current_Tier3_02_Gold = Haven_Tier3_02_Gold;
            int Current_Tier4_01_Gold = Haven_Tier4_01_Gold;
            int Current_Tier4_02_Gold = Haven_Tier4_02_Gold;
            int Current_Tier5_01_Gold = Haven_Tier5_01_Gold;
            int Current_Tier5_02_Gold = Haven_Tier5_02_Gold;
            int Current_Tier6_01_Gold = Haven_Tier6_01_Gold;
            int Current_Tier6_02_Gold = Haven_Tier6_02_Gold;
            int Current_Tier7_01_Gold = Haven_Tier7_01_Gold;
            int Current_Tier7_02_Gold = Haven_Tier7_02_Gold;
            int Current_Tier1_Pop = Haven_Tier1_Pop;
            int Current_Tier2_Pop = Haven_Tier2_Pop;
            int Current_Tier3_Pop = Haven_Tier3_Pop;
            int Current_Tier4_Pop = Haven_Tier4_Pop;
            int Current_Tier5_Pop = Haven_Tier5_Pop;
            int Current_Tier6_Pop = Haven_Tier6_Pop;
            int Current_Tier7_Pop = Haven_Tier7_Pop;
            Basics();
        }
    [some other code]

I have cleared all code that is not relevant at this time. Points of interest:

  • notice that the variable "Current_Tier1_01_Gold" is given a value at the start.
  • it should be that when "Current_Heaven" is called, it makes it so that "Current_Tier1_01_Gold" is assigned the new value of "Haven_Tier1_01_Gold", which is "15"
  • when "Basics" is called, it should make the text "Gold_Tier1" be that of "Current_Tier1_01_Gold"

problems: - the text of "Gold_Tier1" is "3333" - the initial value of "Current_Tier1_01_Gold", even after "Current_Heaven" is called.

If need be, I can provide the full code, but it is 703 lines long.

Was it helpful?

Solution

Yes, you can integrate files into your project by using resources.

That being said, you should get some books about basic programming and especially arrays.You did however not deserve to be ridiculed in the comments, guys.

OTHER TIPS

I'm going to post an example here for your "bonus question" because formatting is easier than in comments.

public void Current_Haven()
{
    int Current_Tier1_01_Gold = Haven_Tier1_01_Gold;
    //You need to add this line here for the Text to be updated.
    Gold_Tier1.Text = Convert.ToString(Current_Tier1_01_Gold);

}

Now, calling Current_Haven will update the Text property as you want it to.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top