问题描述
你好 Stack Overflow 社区,
Hello Stack Overflow community,
我已经着手为我正在开发的游戏制作安装程序/启动程序的项目,但我目前遇到了一个问题,我希望安装程序在屏幕分辨率的中心打开,使用基本 UI, 看起来像:
I have taken up the project of making an installer/launcher for a game I am working on, and I have currently run into an issue, I want the installer to open in the center of the screen resolution, with the base UI, which looks like:
中间名为MainText"的标签预配置为Configuring",角落还有一个名为label1"的隐藏标签用于调试.
The Label in the center named "MainText" is preconfigured to say "Configuring", there is also a hidden label in the corner named "label1" for debugging purposes.
我目前在 MainForm.cs 中的代码如下,程序路径"是指应用程序所在的当前目录.
The code I currently have inside of the MainForm.cs so far is below,the "programpath" refers to current directory in which the application is inside of.
public MainForm()
{
//Open Window
InitializeComponent();
//placeholder song
System.Media.SoundPlayer player = new System.Media.SoundPlayer(programpath+"\\GTA 4 Loading Screen Normalized No intro.wav");
player.PlayLooping();
//newLaunch();
}
void newLaunch(){
File.Create(programpath+"\\FirstLaunch.lic");
MainText.Visible=true;
MainText.Text="Configuring Machine....\nInstalling DirectX";
Process.Start(programpath+"\\dxwebsetup.exe");
label1.Text=programpath+"\\dxwebsetup.exe";
}
但是,如果我取消注释newLaunch()",则 dxwebsetup 应用程序将打开,然后实际 UI 将打开,主文本显示配置机器....安装 DirectX",并且 label1 显示安装程序的位置.
However, if I uncomment "newLaunch()", the dxwebsetup application opens, then the actual UI opens with the MainText stating "Configuring Machine....Installing DirectX", and label1 saying the location of the installer.
我如何使应用程序本身的 UI 出现,然后在之后开始运行代码....类似于实际的安装程序,但仍然是完全自主的,并自行安装所有内容.
How do I make the UI for the application itself appear then start running the code after....similar to an actual installer, however still being completely autonomous, and installing everything on it's own.
推荐答案
如果我正确理解您的问题,您需要做的就是添加一个处理程序,以便在显示表单时处理.当 InitializeComponent 调用完成时,并不意味着窗体还没有完全打开.
If I'm understanding your problem correctly, all you need to do is add a handler for when the Form is shown. When InitializeComponent is finished calling, it doesn't mean the form has been fully opened yet.
在 InitializeComponent 之后,(或者最好在里面)你可以简单地添加
After InitializeComponent, (or preferrably inside) you could simply add
Load += OnLoad;
关注
public void OnLoad(object sender, EventArgs e)
{
}
您可以在其中添加或调用启动功能.
Which is where you can add or call the launch function.
这篇关于如何在C#中打开图形然后执行命令脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!