简体   繁体   English

不同类别中的同一对象?

[英]Same object in different classes?

I've been coding a Minecraft launcher using Windows Forms. 我一直在使用Windows窗体对Minecraft启动器进行编码。 I made it download the launcher if it doesn't detect one. 如果没有检测到启动程序,我就下载了启动程序。 The variable for the EXE is called _exe (I used a get-set for it). EXE的变量称为_exe (我使用了它的获取集)。 I made another form download the launcher async (for a progress bar, talk about aesthetics!). 我制作了另一个表格,以异步方式下载启动器(有关进度栏,请谈美学!)。 In Program.cs , where all the big stuff happens (where Main() is), I have a method called Boot() which loads all the settings and checks for missing files (Minecraft.exe, Launch.bat (which sets the environment variable %APPDATA% because I have no idea how to set environment variables and launch Minecraft with that). When the DownloadLauncher form initializes, it tells me that it's downloading to the folder the launcher is in (which is the default option) although in the settings it's already set to use the original %APPDATA% folder. I know this is a case of objects being declared numerous times but I have no idea how to fix it because it's on such a large scale. Program.cs ,发生了所有大事(在Main()所在的地方),我有一个称为Boot()的方法,该方法会加载所有设置并检查丢失的文件(Minecraft.exe,Launch.bat(用于设置环境)变量%APPDATA%因为我不知道如何设置环境变量并用它启动Minecraft。当DownloadLauncher表单初始化时,它告诉我它是下载到启动器所在的文件夹中(这是默认选项),尽管位于设置它已经设置为使用原始%APPDATA%文件夹了,我知道这是一个对象被多次声明的情况,但是我不知道如何解决它,因为它的规模如此之大。
Program.cs , DownloadLauncher.cs Program.csDownloadLauncher.cs
Problem is that the variable prog._rw.var._exe in line 23 isn't supposed to be .minecraft\\Minecraft.exe but (%APPDATA%)\\.minecraft\\Minecraft.exe 问题在于,第23行中的变量prog._rw.var._exe不应为.minecraft\\Minecraft.exe而是(%APPDATA%)\\.minecraft\\Minecraft.exe

public static class VariableStore
{
    public static string MinecraftPath
    {
        get;
        set;
    }
}

Now to 'set' your variable, you'd call: 现在要“设置”变量,您可以调用:

VariableStore.MinecraftPath = "%appdata%\\roaming\\.minecraft";

You access it the same way: 您可以通过以下方式进行访问:

System.Diagnostics.Debug.Print(VariableStore.MinecraftPath);

Keep in mind that this is a very crude solution. 请记住,这是一个非常粗糙的解决方案。 Also, if you're planning to go through with your project (which sounds like a really nice learning project), I'd advice you to read up a little bit more about WinForms and how they work before you go any further, as you have multiple design flaws already. 另外,如果您打算完成您的项目(听起来像是一个非常不错的学习项目),我建议您在继续之前进一步阅读一些有关WinForms及其工作方式的知识。已经有多个设计缺陷。 Don't give up and good luck! 不要放弃,祝你好运! :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM