SecondEmeraldMaster Posted April 28, 2013 Share Posted April 28, 2013 I've begun to work on a new mod that is supposed to work along side another mod I've been working on lately. Seeing as how I'm new to using C#, this is gonna take some time before I finish it. When I plan on releasing a beta, I'm not sure yet. Right now, I've been trying to do a few things... Write entered values within text boxes to an *.ini file Save file that is currently open in the application (not save as) Undo/Redo functions ...And now I need some help with that. What am I supposed to do now? Any help would be greatly appreciated. Here's the code below of what I have so far: using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace Bus_Driver_Control_Panel{ public partial class MainWindow : Form { public MainWindow() { InitializeComponent(); } private void NewFile_Click(object sender, EventArgs e) { EnterRouteNumber.Clear(); EnterRouteName.Clear(); EnterRouteDestination.Clear(); EnterVIA1stDestination.Clear(); EnterVIA2ndDestination.Clear(); EnterVIA3rdDestination.Clear(); EnterVIA4thDestination.Clear(); EnterVIA5thDestination.Clear(); ServesLocations.Clear(); } private void OpenFile_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Configuration File (*.ini)|*.ini|All Files (*.*)|*.*"; ofd.Title = "Open File"; if (ofd.ShowDialog() == DialogResult.OK) { System.IO.StreamReader sr = new System.IO.StreamReader(ofd.FileName); MessageBox.Show(sr.ReadToEnd()); sr.Close(); } } private void SaveFile_Click(object sender, EventArgs e) { //Right here is where the file that is open is supposed to be saved, but I'm not sure of what the code is. } private void SaveFileAs_Click(object sender, EventArgs e) { SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "Configuration File (*.ini)|*.ini|All Files (*.*)|*.*"; sfd.Title = "Save File As"; sfd.ShowDialog(); if (sfd.FileName != "") { System.IO.FileStream fs = (System.IO.FileStream)sfd.OpenFile(); } } private void CloseFile_Click(object sender, EventArgs e) { Application.Restart(); } private void ExitApplication_Click(object sender, EventArgs e) { Application.Exit(); } }} Link to comment Share on other sites More sharing options...
pedro2555 Posted April 28, 2013 Share Posted April 28, 2013 Is there a good reason for you to avoid Sctiphook's SettingsFile Class ? It would have made your life much easier. Take a look on that, here's the documentation for it -> http://www.hazardx.com/details.php?file=89 But if you happen to have a good reason not use that class, this is pretty huge request to put here. That said here are some guidelines : Write entered values within text boxes to an *.ini file You can have a read-only template file, with some keywords that you change in order to create the new ini file. String.Replace method should do the job. Save file that is currently open in the application (not save as) Technically no file is opened in the application you posted, but what does this differ from the first point ? Isn't the same thing ? Or is it the first a 'Save As' and this one a 'Save' function (if yes, the only thing that changes is the filename)? Undo/Redo functions Undo / Redo is a project on itself, mainly because you need to implement a 'Do' as well. You need to commit all changes the user makes to somewhere, and then you can go back and forth between your records. But I do suggest you to take some time to read about this type of feature, instead of waiting for someone to do it for you. Here is an excelent article on that subject -> http://www.codeproject.com/Articles/19550/...-Generics-NET-C Hope this can help you. Link to comment Share on other sites More sharing options...
freshgamer10 Posted April 28, 2013 Share Posted April 28, 2013 (edited) That's how it should work, but I didn't paste the code into VS, so if it doesn't work, it's most likely because I mixed up the order of the arguments in the File.WriteAllText-Statement. using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace Bus_Driver_Control_Panel{ public partial class MainWindow : Form { string text; //variable which will hold the text of the .ini string filePath; //will hold the file path of the .ini public MainWindow() { InitializeComponent(); } private void NewFile_Click(object sender, EventArgs e) { EnterRouteNumber.Clear(); EnterRouteName.Clear(); EnterRouteDestination.Clear(); EnterVIA1stDestination.Clear(); EnterVIA2ndDestination.Clear(); EnterVIA3rdDestination.Clear(); EnterVIA4thDestination.Clear(); EnterVIA5thDestination.Clear(); ServesLocations.Clear(); } private void OpenFile_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Configuration File (*.ini)|*.ini|All Files (*.*)|*.*"; ofd.Title = "Open File"; if (ofd.ShowDialog() == DialogResult.OK) { filePath = ofd.FileName; //setting the filepath to the file the user selected System.IO.StreamReader sr = new System.IO.StreamReader(filePath); //using variables is always good text = sr.ReadToEnd(); //setting our text MessageBox.Show(text); //again, variables make it less complicated sr.Close(); } } private void SaveFile_Click(object sender, EventArgs e) { File.WriteAllText(text, filePath, Encoding.UTF8); //simple method, it will also replace any file which has been there before } private void SaveFileAs_Click(object sender, EventArgs e) //you should re-code this void { SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "Configuration File (*.ini)|*.ini|All Files (*.*)|*.*"; sfd.Title = "Save File As"; sfd.ShowDialog(); if (sfd.FileName != "") { System.IO.FileStream fs = (System.IO.FileStream)sfd.OpenFile(); } } private void CloseFile_Click(object sender, EventArgs e) { Application.Restart(); } private void ExitApplication_Click(object sender, EventArgs e) { Application.Exit(); } }} Edited April 28, 2013 by freshgamer10 Link to comment Share on other sites More sharing options...
pedro2555 Posted April 28, 2013 Share Posted April 28, 2013 everyone is watching ... Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now