【问题标题】:how to start 123.exe after pushed save button?按下保存按钮后如何启动 123.exe?
【发布时间】:2012-05-31 15:41:49
【问题描述】:

我在 C# 中有一些代码,用于将一些数据保存在 alterIWnet.ini 文件中,因此在将数据保存到 alterIWnet.ini 文件后,表单会关闭。

但在我按下保存按钮后,我希望将数据保存在 alterIWnet.ini 文件中,然后打开 123.exe 文件。

我必须在这份工作中添加什么代码?

我的 C# 代码:

namespace configure_alteriwnet
{
using configure_alteriwnet.Properties;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

public class frmConfig : Form
{
    private Button button1;
    private IContainer components;
    private Label label1;
    private PictureBox pictureBox1;
    private TextBox textBox1;

    public frmConfig()
    {
        this.InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        if ((this.textBox1.Text == "") || (this.textBox1.Text.Length > 80))
        {
            MessageBox.Show("The entered nickname is invalid.", "alterIWnet", MessageBoxButtons.OK, MessageBoxIcon.Hand);
        }
        else
        {
            new IniReader(@".\\alterIWnet.ini").Write("Configuration", "Nickname", this.textBox1.Text);
            base.Close();
        }
    }

    protected override void Dispose(bool disposing)
    {
        if (disposing && (this.components != null))
        {
            this.components.Dispose();
        }
        base.Dispose(disposing);
    }

    private void frmConfig_Load(object sender, EventArgs e)
    {
        this.textBox1.Text = new IniReader(@".\\alterIWnet.ini").ReadString("Configuration", "Nickname", "UnknownPlayer");
    }

    private void InitializeComponent()
    {
        this.pictureBox1 = new System.Windows.Forms.PictureBox();
        this.textBox1 = new System.Windows.Forms.TextBox();
        this.label1 = new System.Windows.Forms.Label();
        this.button1 = new System.Windows.Forms.Button();
        ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
        this.SuspendLayout();
        // 
        // pictureBox1
        // 
        this.pictureBox1.Location = new System.Drawing.Point(13, 13);
        this.pictureBox1.Name = "pictureBox1";
        this.pictureBox1.Size = new System.Drawing.Size(650, 120);
        this.pictureBox1.TabIndex = 0;
        this.pictureBox1.TabStop = false;
        // 
        // textBox1
        // 
        this.textBox1.Location = new System.Drawing.Point(245, 156);
        this.textBox1.Name = "textBox1";
        this.textBox1.Size = new System.Drawing.Size(200, 20);
        this.textBox1.TabIndex = 1;
        this.textBox1.Text = "UnknownPlayer";
        // 
        // label1
        // 
        this.label1.AutoSize = true;
        this.label1.ForeColor = System.Drawing.Color.White;
        this.label1.Location = new System.Drawing.Point(316, 140);
        this.label1.Name = "label1";
        this.label1.Size = new System.Drawing.Size(58, 13);
        this.label1.TabIndex = 2;
        this.label1.Text = "Nickname:";
        // 
        // button1
        // 
        this.button1.Location = new System.Drawing.Point(299, 182);
        this.button1.Name = "button1";
        this.button1.Size = new System.Drawing.Size(75, 23);
        this.button1.TabIndex = 3;
        this.button1.Text = "Save";
        this.button1.UseVisualStyleBackColor = true;
        this.button1.Click += new System.EventHandler(this.button1_Click);
        // 
        // frmConfig
        // 
        this.BackColor = System.Drawing.Color.Black;
        this.ClientSize = new System.Drawing.Size(674, 215);
        this.Controls.Add(this.button1);
        this.Controls.Add(this.label1);
        this.Controls.Add(this.textBox1);
        this.Controls.Add(this.pictureBox1);
        this.Name = "frmConfig";
        this.Text = "alterIWnet MW2 configuration";
        this.Load += new System.EventHandler(this.frmConfig_Load);
        ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
        this.ResumeLayout(false);
        this.PerformLayout();

    }
}
}

【问题讨论】:

    标签: c# add


    【解决方案1】:

    像这样使用System.Diagnostics.@987654321@.@987654322@

    Process.Start("123.exe");
    

    【讨论】:

    • 谢谢,我必须在哪里添加这个,所以在我按下保存按钮后,123.exe 开始启动?
    • 我使用 System.Diagnostics.Process 添加这个;和 Process.Start("123.exe");但我收到此错误:当前上下文中不存在名称“进程”
    • 在您的 bin 文件夹中添加 123.exe。或将 .exe 的完整路径作为 Start() 事件的参数。
    • Start()Process 类在System.Diagnostics 命名空间中的方法。因此,您可以通过 using System.Diagnostics; 包含它
    【解决方案2】:

    在命名空间中添加以下行

    导入 System.Diagnostics.Process;

    在按钮的点击事件中添加下面一行。

    Process.Start("123.exe");

    【讨论】:

    • 谢谢,我必须在哪里添加这个,所以在我按下保存按钮后,123.exe 会开始吗? – ramin esmailinagad
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-19
    • 1970-01-01
    • 1970-01-01
    • 2012-08-23
    • 1970-01-01
    相关资源
    最近更新 更多