Форум программистов, компьютерный форум, киберфорум
C# для начинающих
Войти
Регистрация
Восстановить пароль
Карта форума Темы раздела Блоги Сообщество Поиск Заказать работу  
 
0 / 0 / 0
Регистрация: 06.06.2015
Сообщений: 2
1

Кнопка "Вернуться в главное меню"

06.06.2015, 12:19. Показов 1792. Ответов 0
Метки нет (Все метки)

Author24 — интернет-сервис помощи студентам
Здравствуйте. Подскажите как сделать чтобы в окне "Добавить пиццу" после того как, мы заполним все поля снизу в пределах рамки была кнопка "Вернуться в главное меню" которая возвращает нас в гл меню.

Кнопка "Вернуться в главное меню"


Сам код:
Кликните здесь для просмотра всего текста
C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
 
namespace DreamPizza2
{
    class Program
    {
        static void MessageBox(int x, int y, string msg)
        {
            int w = msg.Length + 4;
            DrawFrame(x, y, w,2);
            Console.SetCursorPosition(x+2, y+1);
            Console.Write(msg);
        }
        
        static void DrawFrame(int x, int y, int w, int h)
        {
            Console.SetCursorPosition(x, y);
            Console.Write("╔"); // 201
            Console.SetCursorPosition(x+w, y);
            Console.Write("╗"); // 187
            Console.SetCursorPosition(x, y+h);
            Console.Write("╚"); // 200
            Console.SetCursorPosition(x+w, y + h);
            Console.Write("╝"); // 188
            // Volcov commander // DOS
            // Norton commander // DOS
            for (int i = 0; i < h-1; i++)
            {
                Console.SetCursorPosition(x, y+1+i);
                Console.Write("║");// 186
                for (int j = 0; j < w; j++)
                {
                    Console.Write(" ");
                }
                Console.SetCursorPosition(x+w, y + 1 + i);
                Console.Write("║");// 186
            }
            for (int i = 0; i < w-1; i++)
            {
                Console.SetCursorPosition(x+1+i, y);
                Console.Write("═");// 205
                Console.SetCursorPosition(x+1+i, y +h);
                Console.Write("═");// 205
            }
            
        }
        static void pod4erk(int x, int y, int w)
        {
            for (int i = 1; i < w+8; i++)
            {
                Console.SetCursorPosition(x+9+i,6);
                Console.Write("─");// 196
                
            }
 
 
        }
 
        static string MyReadLine(int length)
        {
            int x = Console.CursorLeft;
            int y = Console.CursorTop;
            int xstart = x;
            int count = 0;
            string text = "";
            while (true)
            {
                Console.Title = x.ToString();
                ConsoleKeyInfo info = Console.ReadKey(true);
                if (info.Key == ConsoleKey.LeftArrow)
                {
                    if (x > xstart)
                    {
                        x--;
                        Console.SetCursorPosition(x, y);
                    }
                    continue;
                }
                if (info.Key == ConsoleKey.RightArrow)
                {
                    if (x - xstart < count)
                    {
                        x++;
                        Console.SetCursorPosition(x, y);
                    }
                    continue;
                }
                #region Вставка нового символа в текст
                if (count < length)
                    if (!char.IsControl(info.KeyChar))
                    {
                        // находим место курсора в тексте
                        int index = x - xstart;
                        text = text.Insert(index, info.KeyChar + "");
                        // text += info.KeyChar;
                        count++;
                        // Console.Write(info.KeyChar);
                        x++;
                        Console.SetCursorPosition(xstart, y);
                        Console.Write(text);
                        Console.SetCursorPosition(x, y);
                        continue;
                    }
                #endregion
                if (info.Key == ConsoleKey.Backspace)
                {
                    // находим место, где курсор
                    int index = x - xstart;
                    if (index == 0) continue;
                    // удаляем букву перед курсором в тексте
                    text = text.Remove(index - 1, 1);
                    // покажем на экране текст без буквы
                    Console.SetCursorPosition(xstart, y);
                    Console.Write(text + " ");
                    if (x > xstart) x--;
                    Console.SetCursorPosition(x, y);
                    count--;
                    continue;
                }
                if (info.Key == ConsoleKey.Delete)
                {
                    // находим место, где курсор
                    int index = x - xstart;
                    // удаляем букву перед курсором в тексте
                    text = text.Remove(index, 1);
                    // покажем на экране текст без буквы
                    Console.SetCursorPosition(xstart, y);
                    Console.Write(text + " ");
                    Console.SetCursorPosition(x, y);
                    count--;
                    continue;
                }
 
                if (info.Key == ConsoleKey.Enter)
                    break;
            }
            return text;
        }
 
        static string WhiteSpaces(int N) // белые спробелы
        {
            string st = " ";
            for (int i = 0; i < N; i++)
            {
                st += " ";
            }
            return st;
        }
 
        static void EntryToNotebook(string[] mass, string[] mass2) // - Метод который записывает введенные данные из "Добавить пиццу" в txt.
        {
            string fname = "AddPizza.txt";
            FileStream fs = new FileStream(fname, FileMode.Create);
            StreamWriter sr = new StreamWriter(fs);
 
            for (int i = 0; i < 4; i++)
            {
                sr.Write("{0} : ", mass2[i]);
                sr.WriteLine("{0}", mass[i]);
                
            }
 
            sr.Close();
            fs.Close();
            Console.ReadLine();
 
        }
 
        static void FormInputPizza() // Метод добавляет новую пиццу
        {
 
            Console.BackgroundColor = ConsoleColor.Black;
            Console.Clear();
            string[] menu = { "Название:", "Состав:", "Стоимость:", "Что-там:"};
            Console.ForegroundColor = ConsoleColor.White;
            Console.BackgroundColor = ConsoleColor.DarkCyan;
            int x = 4, y = 2;
            DrawFrame(x, y, 60, 18);
            Console.SetCursorPosition(x+3, y);
            Console.Write("[Добавление новой пиццы]");
 
            //слева меню( Название: и т.д.)
            for (int i = 0; i < 4; i++)
            {
                Console.BackgroundColor = ConsoleColor.DarkCyan;
                Console.SetCursorPosition(x +2, y + 3 + i * 2);
                Console.Write(menu[i]);
                Console.BackgroundColor = ConsoleColor.DarkGray;
                Console.SetCursorPosition(x+12, y+3+i*2);
                Console.Write(WhiteSpaces(25));
            }
            // ВВод
            string[] data = new string[4];
 
            for (int i = 0; i < 4; i++)
            {
                
                Console.SetCursorPosition(x + 12, y + 3 + i * 2);
                Console.BackgroundColor = ConsoleColor.Gray;
                Console.Write(WhiteSpaces(25));
                Console.SetCursorPosition(x + 12, y + 3 + i * 2);
                Console.ForegroundColor = ConsoleColor.Black;
                data[i] = MyReadLine(20);
                // возвращаем серую подстветку
                Console.SetCursorPosition(x + 12, y + 3 + i * 2);
                Console.BackgroundColor = ConsoleColor.Gray;
                Console.ForegroundColor = ConsoleColor.Black;
                Console.Write(WhiteSpaces(25));
                Console.SetCursorPosition(x + 12, y + 3 + i * 2);
                Console.Write(data[i]);
                
            }
            EntryToNotebook(data, menu);
 
           
            
 
            //-----------------------------------------------------
        }
 
        static void OrderPizza()
        {
 
            Console.BackgroundColor = ConsoleColor.Black;
            Console.Clear();
            string[] menu = { "ФИО*", "Телефон*", "Улица*", "Дом*" };
            Console.ForegroundColor = ConsoleColor.White;
            Console.BackgroundColor = ConsoleColor.DarkCyan;
            int x = 4, y = 2;
            DrawFrame(x, y, 50, 25);
            Console.SetCursorPosition(x + 20, y);
            Console.Write("[ЗАКАЗ ПИЦЦЫ]");
            Console.SetCursorPosition(x + 5, 17);
            Console.Write("* Поля обязательны для заполнения");
    
 
            //слева меню
            for (int i = 0; i < 4; i++)
            {
                Console.BackgroundColor = ConsoleColor.DarkCyan;
                Console.SetCursorPosition(x + 5, y + 3 + i * 3);
                Console.Write(menu[i]);
                Console.BackgroundColor = ConsoleColor.DarkGray;
                Console.SetCursorPosition(x + 15, y + 3 + i * 3);
                Console.Write(WhiteSpaces(25));
            }
            
            // ВВод
            for (int i = 0; i < 4; i++)
            {
                Console.SetCursorPosition(x + 15, y + 3 + i * 3);
                Console.BackgroundColor = ConsoleColor.Gray;
                Console.Write(WhiteSpaces(25));
                Console.SetCursorPosition(x + 15, y + 3 + i * 3);
                Console.ForegroundColor = ConsoleColor.Black;
                string text = MyReadLine(20);
                // возвращаем серую подстветку
                Console.SetCursorPosition(x + 15, y + 3 + i * 3);
                Console.BackgroundColor = ConsoleColor.Gray;
                Console.ForegroundColor = ConsoleColor.Black;
                Console.Write(WhiteSpaces(25));
                Console.SetCursorPosition(x + 15, y + 3 + i * 3);
                Console.Write(text);
 
            }
        }
 
        static int Menu (string[] menu, int X, int Y)
        {
            int active = 0;
            while(true)
            {
                DrawMenu(menu, X, Y, active);
                ConsoleKeyInfo info = Console.ReadKey(true);
                switch (info.Key)
                {
                    case ConsoleKey.DownArrow://Если была клацнута кнопка "вниз" - нужно повысить элемент на 1 единицу, т.е. сдвинуть его на 1 элемент ниже.
                        if (active == menu.Length-1)//Проверим ка, а не последний ли это элемент в меню.
                        {
                            active = 0;//Если так и есть, значит это правда. Переместим ка его на самый первый элемент меню.
                        } else
                        active++;//Теперь можно дальше повышать его индекс.
                        break;
                    case ConsoleKey.UpArrow://Если вдруг клиенту захотелось жмыхнуть кнопку "вверх", значит мы понижаем его индекс на 1.
                        if (active == 0)
                        {
                            active = menu.Length-1;//Проверим, а не первый ли элемент уже выбран? Если да, то сделаем его последним и идём дальше.
                        } else
                        active--;//Теперь можно спокойно понижать его индекс на 1.
                        break;
                    case ConsoleKey.Enter: //как только нажат энтер - метод завершается.
                        return active;
                }
            }   
        }
        static void DrawMenu(string[] menu, int X, int Y, int active)
        {
            
            
            Console.BackgroundColor = ConsoleColor.DarkCyan;
            Console.ForegroundColor = ConsoleColor.Black;
            for (int i = 0; i < menu.Length; i++)
            {
                Console.SetCursorPosition(X, Y+i*2);//На всякий случай сдвинем меню на 8 единиц по Х, чтобы не мешать главному меню. Элементы прорисовываются с шагом "начальная точка+№ элемента".
                Console.Write(menu[i]);//Координаты определены, прорисовываем элемент.
            }
            //Выбираем активный элемент, изменяя цвета фона и текста.
            Console.BackgroundColor = ConsoleColor.DarkGray;
            Console.ForegroundColor = ConsoleColor.Black;
            Console.SetCursorPosition(X, Y+ active*2);//Выбираем активный элемент. Те же координаты, только сдвиг "начальная координата+активный элемент из меню Select".
 
            Console.Write(menu[active]);
        }
   
 
        static void Main(string[] args)
        {
            Console.BackgroundColor = ConsoleColor.Black;
            Console.Clear();
            while (true)
            {
 
                string[] menu0 =
                {
                    "Добавить пиццу", "Заказать пиццу", "Менеджер", "Выход"
 
                };
                
                string[][] all = { menu0};
 
 
                while (true)
                {
                    Console.BackgroundColor = ConsoleColor.Black;
                    Console.Clear();
 
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.BackgroundColor = ConsoleColor.DarkCyan;
                    DrawFrame(18, 2, 30, 20);
                    pod4erk(10, 10,20);
                    Console.SetCursorPosition(27, 4);
                    Console.Write("Главное меню");
                    
                    int n = Menu(menu0, 27, 8);
                    switch(n)
                    { 
                        case 0:
                            FormInputPizza();
                            break;
                        case 1:
                            OrderPizza();
                            break;
                        case 2:
                            break;
                        case 3:
                            return;
 
                    }
                   
                }
 
 
            
 
                Console.ReadLine();
                // Главное меню
                
                
            }
 
            Console.ReadLine();
        }
    }
}
0
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
06.06.2015, 12:19
Ответы с готовыми решениями:

Как вернуться в главное меню!
Всем привет!Я сделал простенькую программу,которая записывает что-то в файл и выводит то,что...

Заменить главное меню на другое главное меню
Здравствуйте. Помогите, пожалуйста, с задачей: &quot;Создать приложение, в котором при нажатии на кнопку...

Кнопка вернуться.
Я смог с помощью кода отправить с одной аппликейшион форм на другую, но не знаю как сделать что бы...

Кнопка вернуться назад на js
Всем доброго времени суток ! Мне необходимо при нажатии на ссылку перейти на новую вкладку...

Как сделать возврат в главное меню из подпункта меню, здесь код в (.h) и (.cpp)
(.h)Header.h #pragma once using namespace std; class Adress { public: Adress(string...

0
06.06.2015, 12:19
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
06.06.2015, 12:19
Помогаю со студенческими работами здесь

Возврат назад в главное меню из подпункта меню
Добрый вечер, подскажите пожалуйста, как организовать многоуровневое меню? А конкретно, надо из...

Сделать: Главное меню (первые вторые третьи) после главного меню выбор блюда, в конце список обеда
Создать 3 массива = 1 – супы(борщ, солянка, грибной) 2 - каши(гречка, перловка, манка) 3 –...

Главное меню
Подскажите пожалуйста, как исправить проблему. Есть главное меню, пункт «А» и «Б». В пункте «Б»...

Главное меню
Вот с меню ни как не могу разобраться..жумловское меню встает не по центру контейнера меню...как...

Главное меню
Здравствуйте!!! WP-3.5.1 Моя казалось-бы простая задача : Первые 2 пункта Главного меню должны...

Главное меню
Всем привет! имеется некоторое горизонтальное меню (скрин прилагается), хотелось бы с ним сделать...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
1
Ответ Создать тему
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2024, CyberForum.ru