2012-05-31 42 views
1

我在C#中有一些代碼,它用於在alterIWnet.ini文件中保存一些數據,所以在alterIWnet.ini文件中保存數據後,表單被關閉。如何啓動123.exe後按下保存按鈕?

但是當我按下保存按鈕後,我將數據保存在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(); 

    } 
} 
} 
+1

Process.Start() – jglouie

回答

1

添加以下線的命名空間

進口的System.Diagnostics.Process;

在按鈕的點擊事件中添加以下行。

Process.Start(「123.exe」);

+0

感謝和確切的地方,我必須添加這個,所以我按保存按鈕123.exe去開始? - ramin esmailinagad –

+0

謝謝...解決 –

4

使用System.Diagnostics. Process . Start()像這樣:

Process.Start("123.exe"); 
+0

謝謝,正是我必須添加這個,所以在我按下保存按鈕123.exe去開始? –

+0

我使用System.Diagnostics.Process添加這個;和Process.Start(「123.exe」);但我得到這個錯誤:名稱'進程'不存在於您的bin文件夾中的當前階段 –

+0

添加123.exe。或者將.exe的完整路徑作爲Start()事件的參數。 –