码迷,mamicode.com
首页 > 移动开发 > 详细

How to customize the console applicaton

时间:2015-11-29 18:01:12      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:

下面是如何最大化console和改变其显示的字体颜色的代码,顺便包含了计时代码(帮助做性能分析): 

    class Program
    {
        [DllImport("kernel32.dll", ExactSpelling = true)]
        private static extern IntPtr GetConsoleWindow();
        private static IntPtr ThisConsole = GetConsoleWindow();

        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

        private const int HIDE = 0;
        private const int MAXIMIZE = 3;
        private const int MINIMIZE = 6;
        private const int RESTORE = 9;

        private const int OldestPhaseNo = 2003001;

        static void Main(string[] args)
        {
            // Set maximum console windows size
            Console.SetWindowSize(Console.LargestWindowWidth, Console.LargestWindowHeight);
            ShowWindow(ThisConsole, MAXIMIZE);

            // Start the time watch
            Stopwatch watch = new Stopwatch();
            watch.Start();
            
            // Stop the time wattch
            Dictionary<string, string> ssqRecords = GetSsQiuRecords().Result;
            watch.Stop();

            // Change/Set the console‘s foregound clodr as green
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine(watch.Elapsed.TotalSeconds);

            // Restart the time calculation to 0
            watch.Restart();
            SaveLotteryDataToLocalConfig(ssqRecords);
            watch.Stop();

            Console.WriteLine(watch.Elapsed.TotalSeconds);
            // Revert back to the default color
            Console.ForegroundColor = ConsoleColor.Gray;

            // Set the display buffer for console window
            Console.SetBufferSize(1000, 30000);
        }
    }

 

How to customize the console applicaton

标签:

原文地址:http://www.cnblogs.com/researcher/p/5004970.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!