Breaking News
Loading...
Wednesday, August 22, 2012

Tạo menu cấp 1 đơn giản, cho phép dùng phím mũi tên lên xuống để di chuyển vị trí chọn

8/22/2012 09:55:00 PM

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace Bai16
{
    class 
Program
    
{
        static 
void XuatMenu(int chon)
        {
            
string[] str = {"Chuc nang 1" "Chuc nang 2""Chuc nang 3""Chuc nang 4""Thoat"};
            
int x 20;
            
int[] = {5791113};
            
Console.CursorLeft x;
            
Console.CursorTop 3;
            
Console.ForegroundColor ConsoleColor.White;
            
Console.BackgroundColor ConsoleColor.Black;
            
Console.Write("BAI TAP MENU");

            
Console.ForegroundColor ConsoleColor.Red;
            for (
int i 0str.Lengthi++)
            {
                if (
== chon)
                    
Console.BackgroundColor ConsoleColor.Cyan;
                else
                    
Console.BackgroundColor ConsoleColor.Green;
                
Console.CursorLeft x;
                
Console.CursorTop y[i];
                
Console.Write(str[i]);
            }

        }

        static 
void XuLy()
        {
            
int i 0;
            
ConsoleKeyInfo key;
            while (
true)
            {
                
XuatMenu(i);
                
Console.CursorLeft 40;
                
Console.CursorTop =  18;
                
key Console.ReadKey();
                if (
key.Key == ConsoleKey.DownArrow && 4)
                    
i++;
                if (
key.Key == ConsoleKey.UpArrow && 0)
                    
i--;
                if (
key.Key == ConsoleKey.Enter && == 4)
                    break;
             
                else if(
key.Key == ConsoleKey.Enter)
                    
Console.Write("Ban dang chon chuc nang " +(i+1).ToString());
            }

        }
        static 
void Main(string[] args)
        {
            
XuLy();
        }  

0 comments:

Post a Comment

 
Toggle Footer