Jump to content
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. Los Santos Drug Wars
      2. Updates
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Red Dead Online

      1. Blood Money
      2. Frontier Pursuits
      3. Find Lobbies & Outlaws
      4. Help & Support
    3. Crews

    1. Grand Theft Auto Series

      1. Bugs*
      2. St. Andrews Cathedral
    2. GTA VI

    3. GTA V

      1. Guides & Strategies
      2. Help & Support
    4. GTA IV

      1. The Lost and Damned
      2. The Ballad of Gay Tony
      3. Guides & Strategies
      4. Help & Support
    5. GTA San Andreas

      1. Classic GTA SA
      2. Guides & Strategies
      3. Help & Support
    6. GTA Vice City

      1. Classic GTA VC
      2. Guides & Strategies
      3. Help & Support
    7. GTA III

      1. Classic GTA III
      2. Guides & Strategies
      3. Help & Support
    8. Portable Games

      1. GTA Chinatown Wars
      2. GTA Vice City Stories
      3. GTA Liberty City Stories
    9. Top-Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    1. Red Dead Redemption 2

      1. PC
      2. Help & Support
    2. Red Dead Redemption

    1. GTA Mods

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Red Dead Mods

      1. Documentation
    3. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    4. Featured Mods

      1. Design Your Own Mission
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Rockstar Games

    2. Rockstar Collectors

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Movies & TV
      5. Music
      6. Sports
      7. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. Announcements

    2. Support

    3. Suggestions

Coding for my Bus Driver Control Panel


SecondEmeraldMaster
 Share

Recommended Posts

SecondEmeraldMaster

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

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

freshgamer10

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 by freshgamer10
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.