我对编程比较陌生,现在开始使用C#编写代码。 我正在制作一个小程序,我想只包含一个* .exe文件。 该程序是一个窗体,上面有一些图片,有一些默认的起始和其他需要在某些条件下显示。基本上它们是我用PictureBox.Image = System.Drawing.Image.FromFile(@" C:\ teh image.jpg");
改变的相同PictureBox我使用"选择图像"在图片框上的选项,以找到我的硬盘驱动器上的每个默认图片,并有,发现它们包含在* .exe文件中,如果我更改文件夹的名称(包含图片的名称) )程序运行顺利。我想对我之后需要显示的其他图片做同样的事情,我认为可能是之后我包含了我的.image.from文件等等。全智能的编译器会看到它并包含其他图片,但它没有。所以我想知道如何做到这一点。
作为奖励问题,我的代码中似乎有错误:
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]
我已清除了此时不相关的所有代码。 兴趣点:
问题: - " Gold_Tier1"的文本是" 3333" - " Current_Tier1_01_Gold"的初始值,即使在" Current_Heaven"之后被称为。
如果需要,我可以提供完整的代码,但它长达703行。
答案 0 :(得分:1)
是的,您可以使用resources将文件集成到项目中。
话虽这么说,你应该得到一些关于基本编程的书籍,特别是数组。但是你不应该在评论中被人嘲笑。
答案 1 :(得分:0)
我将在这里发布一个例子,为你的"奖金问题"因为格式化比评论更容易。
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);
}
现在,调用Current_Haven
会根据需要更新Text
属性。