hm... det virker som om den ikke helt kan finde ud af hvor den vil gemme filerne, det er måske det du har haft problemer med. Lige pludselig begyndte programmet at gemme de to filer i roden af c:\... underligt.
Men nu har jeg i hvert fald gjort det mere entydigt hvor at filerne skal gemmes (Application.StartupPath), så nu burde der ikke være mere bøvl med det
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Diagnostics;
using System.IO;
namespace _579489
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Button setRM;
private System.Windows.Forms.Button setZH;
private System.Windows.Forms.TextBox rmpath;
private System.Windows.Forms.TextBox zhpath;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.setRM = new System.Windows.Forms.Button();
this.setZH = new System.Windows.Forms.Button();
this.rmpath = new System.Windows.Forms.TextBox();
this.zhpath = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.setRM);
this.groupBox1.Controls.Add(this.setZH);
this.groupBox1.Controls.Add(this.rmpath);
this.groupBox1.Controls.Add(this.zhpath);
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.groupBox1.Location = new System.Drawing.Point(8, 8);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(344, 128);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Paths";
//
// setRM
//
this.setRM.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.setRM.Location = new System.Drawing.Point(280, 96);
this.setRM.Name = "setRM";
this.setRM.Size = new System.Drawing.Size(56, 20);
this.setRM.TabIndex = 5;
this.setRM.Text = "Set";
this.setRM.Click += new System.EventHandler(this.setRM_Click);
//
// setZH
//
this.setZH.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.setZH.Location = new System.Drawing.Point(280, 40);
this.setZH.Name = "setZH";
this.setZH.Size = new System.Drawing.Size(56, 20);
this.setZH.TabIndex = 4;
this.setZH.Text = "Set";
this.setZH.Click += new System.EventHandler(this.setZH_Click);
//
// rmpath
//
this.rmpath.Location = new System.Drawing.Point(8, 96);
this.rmpath.Name = "rmpath";
this.rmpath.Size = new System.Drawing.Size(264, 20);
this.rmpath.TabIndex = 3;
this.rmpath.Text = "Doubleclick to set RM-path";
this.rmpath.DoubleClick += new System.EventHandler(this.rmpath_DoubleClick);
//
// zhpath
//
this.zhpath.Location = new System.Drawing.Point(8, 40);
this.zhpath.Name = "zhpath";
this.zhpath.Size = new System.Drawing.Size(264, 20);
this.zhpath.TabIndex = 2;
this.zhpath.Text = "Doubleclick to set ZH-path";
this.zhpath.DoubleClick += new System.EventHandler(this.zhpath_DoubleClick);
//
// label3
//
this.label3.Location = new System.Drawing.Point(8, 80);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(168, 23);
this.label3.TabIndex = 1;
this.label3.Text = "Replay Manager path:";
//
// label2
//
this.label2.Location = new System.Drawing.Point(8, 24);
this.label2.Name = "label2";
this.label2.TabIndex = 0;
this.label2.Text = "ZeroHour path:";
//
// button1
//
this.button1.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.button1.Location = new System.Drawing.Point(8, 144);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(344, 23);
this.button1.TabIndex = 1;
this.button1.Text = "Run ZH + RM";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 168);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(344, 23);
this.label1.TabIndex = 3;
this.label1.Text = "Developed by Jeppe Ledet-Pedersen -
www.ledets.dk"; this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(360, 195);
this.Controls.Add(this.label1);
this.Controls.Add(this.button1);
this.Controls.Add(this.groupBox1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.Name = "Form1";
this.Text = "ZHRMBoot - Beta 0.01";
this.Closing += new System.ComponentModel.CancelEventHandler(this.Form1_Closing);
this.Load += new System.EventHandler(this.Form1_Load);
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
try
{
Process.Start(zhpath.Text);
Process.Start(rmpath.Text);
}
catch
{
MessageBox.Show("One or more of the programs could not be found.\nPlease recheck the paths.", "Unknown program", System.Windows.Forms.MessageBoxButtons.OK,System.Windows.Forms.MessageBoxIcon.Error);
}
}
private void setZH_Click(object sender, System.EventArgs e)
{
OpenDialogAndSavePathToTextBox(zhpath);
}
private void setRM_Click(object sender, System.EventArgs e)
{
OpenDialogAndSavePathToTextBox(rmpath);
}
private void zhpath_DoubleClick(object sender, System.EventArgs e)
{
OpenDialogAndSavePathToTextBox(zhpath);
}
private void rmpath_DoubleClick(object sender, System.EventArgs e)
{
OpenDialogAndSavePathToTextBox(rmpath);
}
private void Form1_Load(object sender, System.EventArgs e)
{
try
{
zhpath.Text = ReadTextFromFile("zhpath.dat");
rmpath.Text = ReadTextFromFile("rmpath.dat");
}
catch {}
}
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
DialogResult result = MessageBox.Show("Vil du virkelig lukke programmet?","Luk programmet?",MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
if(result == DialogResult.Yes)
{
SaveTextToFile("zhpath.dat", zhpath.Text);
SaveTextToFile("rmpath.dat", rmpath.Text);
Application.Exit();
}
else
{
e.Cancel = true;
}
}
private void OpenDialogAndSavePathToTextBox(TextBox theBox)
{
// Create a new OpenFileDialog and display it.
OpenFileDialog fd = new OpenFileDialog();
fd.Filter = "Programs(*.exe)|*.exe";
fd.FilterIndex = 1;
if(fd.ShowDialog() == DialogResult.OK)
{
theBox.Text = fd.FileName;
}
else
{
theBox.Text = "Path not selected!";
}
}
private void SaveTextToFile(string file, string text)
{
FileStream fs = new FileStream(Application.StartupPath + "\\"+ file, FileMode.Create, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.UTF8);
sw.Write(text);
sw.Close();
}
private string ReadTextFromFile(string file)
{
FileStream fs = File.OpenRead(file);
StreamReader sr = new StreamReader(fs);
string returnString = sr.ReadLine();
sr.Close();
return returnString;
}
}
}