6 Replies - 249 Views - Last Post: 15 July 2019 - 10:15 AM Rate Topic: -----

#1 Braddylonglegs   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 15-July 19

Need to save contents of Windows Form App

Posted 15 July 2019 - 04:07 AM

Hello

Please forgive me if this is impossible, I'm a total newbie to programming.

I have created a Windows Form Application in Visual Studio which is now running as an .exe file on my PC.
The purpose of the form is to allow me to enter text and upload images into various tabs which I have added with .. I will post screen grabs below.

The problem:

I have added a MenuStrip to the application. I would like to use the "Save as.." button on the menustrip so that I can save the ENTIRE contents of the application(text entries, pictureBox contents and whatever else I add in later).

I have trawled the web for hours reading about things I don't understand, like StreamWriters and BindingNavigators which seem to apply to my issue but I don't see how.

In a nutshell I would just like to "Save as.." a file name which I specify via SaveFileDialog so that when I open the file later, it opens the Windows Form with the contents that were in it when I saved. Ultimately I will have lots of Saved Files, each with different content, which I would like to open later.

Is there some code that I can use to achieve this?

I have added a SaveFileDialog control to the form, and I have double clicked the Save As control which has added a section called "SaveAsToolStripMenuItem_Click" to the coding screen where I need to enter the code for the above issue.

Please see screen grabs for better understanding.

Attached Image

Attached Image

Attached Image

Attached Image

Attached Image

Attached Image

Attached Image

Is This A Good Question/Topic? 0
  • +

Replies To: Need to save contents of Windows Form App

#2 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 7053
  • View blog
  • Posts: 23,977
  • Joined: 05-May 12

Re: Need to save contents of Windows Form App

Posted 15 July 2019 - 05:23 AM

All the SaveAsFileDialog will do is give you a filename to save to. It's still your job to open a stream with that file name, iterate over each of your tabs and then write data out to the stream.

As a quick aside, WinForms is end of life technology (despite the little boost that Microsoft has given it by supporting it for .NET Core 3.0). You really should be learning how to write C# code using Xamarin.Forms or WPF. The reason is that the default approach to using WinForms is to have your data, view, and program logic all bundled into spaghetti code that lives in a "form". This was the way things were done back in 80's and 90's when memory was scarce and every byte mattered because memory (and CPU) was expensive. In modern times, programmer times is expensive (and hence why a lot of outsourcing happens to make programmer time cheaper). By using a more modern approach of MVC or MVVM or MVP that the newer UI frameworks encourage, your task above for loading and saving your data becomes slightly easier. The reason for this is that you can think of your text and images (your data) as separate entities that just happen to be displayed by the UI (your view). So when it is time to load and save, you just address your data directly. Assuming your did WinForms the traditional way, you would need to go through you UI controls to pull the data out for saving, and later when it is time to load, you would have push the data back into the UI controls.
Was This Post Helpful? 0
  • +
  • -

#3 Braddylonglegs   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 15-July 19

Re: Need to save contents of Windows Form App

Posted 15 July 2019 - 07:07 AM

Thank you for taking the time to read and reply to my post.

Unfortunately I do not have the time or the need to become a fully fledged programmer; I am simply attempting to create a simple-as-possible tool that will help me with my day job.

I would swap my internal organs for coding skills but my job takes up 12 - 15 hours per day and learning c# is just not an option at the moment.

The purpose of my post was to find out if it is possible to achieve what I have described above, and I was hoping for some help with the code or perhaps a beginner-level tutorial link that would help me understand the elements of the code that needs to be written.

Any help would be much appreciated.

Best wishes
Braddylonglegs
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15262
  • View blog
  • Posts: 61,166
  • Joined: 12-June 08

Re: Need to save contents of Windows Form App

Posted 15 July 2019 - 07:15 AM

Sure.. if it's a plain old text then Streamwriter or Filewriter would be fine.

https://docs.microso...-text-to-a-file

Use 'savefiledialog' to pick a location and file name.
Use that information as a 'location' parameter for your streamwriter/filewriter.
Use the correct 'write' method.
Close the streamwriter/filewriter and be done.


Loading would be the 'file picker' dialog to get the location.
Using streamREADER/fileREADER, with this location, to get the contents in a string.
Stuff where ever you want in your GUI.
Was This Post Helpful? 0
  • +
  • -

#5 Braddylonglegs   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 15-July 19

Re: Need to save contents of Windows Form App

Posted 15 July 2019 - 07:50 AM

[quote name='modi123_1' date='15 July 2019 - 07:15 AM' timestamp='1563200122' post='2401982']
Sure.. if it's a plain old text then Streamwriter or Filewriter would be fine.






Thank you Beardy .. unfortunately it isn't just text, there are also images in pictureboxes so it is a mixture of content types (multiple text boxes and image boxes) that needs to be saved, as per the screenshots I uploaded.

Is this even possible or would I need to completely re-write the app in some other software?


Thank you
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15262
  • View blog
  • Posts: 61,166
  • Joined: 12-June 08

Re: Need to save contents of Windows Form App

Posted 15 July 2019 - 08:06 AM

Beardy?

Ah, yeah.. you can save images..



https://docs.microso...wing.image.save

Https://docs.microso...ialog-component
Was This Post Helpful? 0
  • +
  • -

#7 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 7053
  • View blog
  • Posts: 23,977
  • Joined: 05-May 12

Re: Need to save contents of Windows Form App

Posted 15 July 2019 - 10:15 AM

Yes, but the fun part for the OP will be figuring out how separate the text and image data within the same stream. Since he doesn't want to learn how to be a developer, he is going to run into issues unless he uses some kind of pre-made class that can handle multiple streams stored in a single stream. Something like the ZipArchive class.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1