Help with the implementation of ideas please on c # windows forms. The bottom line is:

The user has installed the application. Launches it; when you first start, a window appears with a choice of his position, for example: category 1 cook, category 2 cook, category 3 cook, etc. The selected window opens, for example, a chef of category 2. (The selected window is saved somewhere in the user settings). The user has worked and closed the program.

The next time you start the program, the settings are read and the cooker window of category 2 opens immediately. Possibility in the future to change in the settings if necessary from the cook 2 categories to the cook 1 category.

Closed due to the fact that the question is too general for the participants fori1ton , HamSter , rdorn , Denis , ermak0ff 11 Nov '16 at 7:01 .

Please correct the question so that it describes the specific problem with sufficient detail to determine the appropriate answer. Do not ask a few questions at once. See “How to ask a good question?” For clarification. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • Specify the question. You do not know how to save the settings to a file, in what format to save and how then to read it, or something else? - eastwing
  • Specify how best to save the setting. And how to make it so that When you first start the program there was a choice. And from the second launch, the user-selected form was launched. - Michael
  • Read something like "working with files in c #" if you want to save to a file. If you want to save not to a file, read how to work with it. - nick_n_a
  • There are lots of ways to save settings, for example, to the App.config file, to the database, to your file, etc. I would break your task into 2: 1. Decide what exactly to keep? 2. How exactly to save? - BlackWitcher
  • About saving the settings read. Let's call forms 1 cook 1povar.cs, 2 cook 2.cs save them in a file under the variable formPovarStart. How now in program.cs to specify reading of settings and what form to load? And how at the first start I loaded the form with the choice of opening the form of cooks by default? - Michael

1 answer 1

Briefly about working with files. Consider a primitive console application:

using System; using System.IO; namespace playground { class Program { //Допустим, категория просто определяется цифрой (1 - Повар первой категории, и т.п.)? //которую мы для простоты будем хранить в виде строки (т.е. в текстовом виде) public static string Category; static void Main(string[] args) { //Если файла с настройками нет - условно, первый запуск приложения if (!File.Exists("settings.txt")) { // Console.Write("Укажите категорию повара: "); //Пользователь вводит цифру, обозначающую категорию Category = Console.ReadLine(); //...И, собственно, сохраняем её в файл File.WriteAllText("settings.txt", Category); } //Файл с настройками найден, читаем из него данные else { Category = File.ReadAllText("settings.txt"); } //После того, как пользователь указал категорию (если это первый запуск), или программа считала её из файла (если не первый), выведем информацию в консоль: Console.WriteLine($"Повар {Category} категории"); Console.ReadKey(); } } } 

String using System.IO; Mandatory, it lets you say, gives you access to the methods of working with files (among other things).

Next, pay attention to if (!File.Exists("settings.txt")) - here we check for the presence of the file "settings.txt". In general, the full path to the file is passed as an argument (you can use environment variables ), in this case it checks for the presence of a file next to the program (in the same folder).

If the file is not found, the user is prompted to enter a number: Category = Console.ReadLine(); Which is immediately written to the file: `File.WriteAllText (" settings.txt ", Category);

If the file already exists, the program simply reads the number from the file: Category = File.ReadAllText("settings.txt");

I repeat, this example is very primitive. Read the manual , you can, of course, write to the file much more complex structures than just the value of one variable.

In general, as already noted in the comments, there is a huge variety of ways to store program data, just writing to a file is far from the only one.

  • Thank. I start to understand, and windows forms could not write an example please. - Michael
  • What's the problem? Approximately the same: no file - the selection form opens, there is - read a category from it, show the corresponding information. If you do not know how to work with WinForms, then it is more correct to ask a separate question. - eastwing
  • It is exactly the moment when I read the configuration file and open the form. Switch case I think to use - Michael