<tfoot id='534Kl'></tfoot>

  • <small id='534Kl'></small><noframes id='534Kl'>

    • <bdo id='534Kl'></bdo><ul id='534Kl'></ul>
  • <legend id='534Kl'><style id='534Kl'><dir id='534Kl'><q id='534Kl'></q></dir></style></legend>

      1. <i id='534Kl'><tr id='534Kl'><dt id='534Kl'><q id='534Kl'><span id='534Kl'><b id='534Kl'><form id='534Kl'><ins id='534Kl'></ins><ul id='534Kl'></ul><sub id='534Kl'></sub></form><legend id='534Kl'></legend><bdo id='534Kl'><pre id='534Kl'><center id='534Kl'></center></pre></bdo></b><th id='534Kl'></th></span></q></dt></tr></i><div id='534Kl'><tfoot id='534Kl'></tfoot><dl id='534Kl'><fieldset id='534Kl'></fieldset></dl></div>

        在屏幕左下角放置一个小控制台窗口?

        时间:2023-08-27
        1. <i id='k1pa1'><tr id='k1pa1'><dt id='k1pa1'><q id='k1pa1'><span id='k1pa1'><b id='k1pa1'><form id='k1pa1'><ins id='k1pa1'></ins><ul id='k1pa1'></ul><sub id='k1pa1'></sub></form><legend id='k1pa1'></legend><bdo id='k1pa1'><pre id='k1pa1'><center id='k1pa1'></center></pre></bdo></b><th id='k1pa1'></th></span></q></dt></tr></i><div id='k1pa1'><tfoot id='k1pa1'></tfoot><dl id='k1pa1'><fieldset id='k1pa1'></fieldset></dl></div>

              <bdo id='k1pa1'></bdo><ul id='k1pa1'></ul>

                <tfoot id='k1pa1'></tfoot>

                <small id='k1pa1'></small><noframes id='k1pa1'>

                <legend id='k1pa1'><style id='k1pa1'><dir id='k1pa1'><q id='k1pa1'></q></dir></style></legend>
                    <tbody id='k1pa1'></tbody>

                • 本文介绍了在屏幕左下角放置一个小控制台窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  正如标题所说,我想将它定位在屏幕的左下角.这是我到目前为止的代码:

                  As the title says, I want to position it to the bottom left corner of the screen. Here's the code I have so far:

                      Console.WindowWidth = 50
                      Console.WindowHeight = 3
                      Console.BufferWidth = 50
                      Console.BufferHeight = 3
                      Console.BackgroundColor = ConsoleColor.Black
                      Console.ForegroundColor = ConsoleColor.DarkMagenta
                      Console.Title = "My Title"
                      Console.WriteLine("")
                      Console.Write(" Press any key to close this window ...")
                  
                      Console.ReadKey()
                  

                  推荐答案

                  可以使用System.Console<的Console.WindowTopConsole.WindowWidth/code> 类来设置控制台窗口的位置.

                  You can use Console.WindowTop and Console.WindowWidth of the System.Console class to set the location of the console window.

                  这里是 MSDN 上的一个例子

                  Here is an example on MSDN

                  BufferHeightBufferWidth 属性获取/设置要显示的行数和列数.

                  The BufferHeight and BufferWidth property gets/sets the number of rows and columns to be displayed.

                  WindowHeightWindowWidth 属性必须始终分别小于 BufferHeightBufferWidth.

                  WindowHeight and WindowWidth properties must always be less than BufferHeight and BufferWidth respectively.

                  WindowLeft 必须小于 BufferWidth - WindowWidth 并且 WindowTop 必须小于 BufferHeight - WindowHeight.

                  WindowLeft must be less than BufferWidth - WindowWidth and WindowTop must be less than BufferHeight - WindowHeight.

                  WindowLeftWindowTop 是相对于缓冲区的.

                  WindowLeft and WindowTop are relative to the buffer.

                  要移动实际的控制台窗口,这篇文章有一个很好的例子.

                  To move the actual console window, this article has a good example.

                  我使用了您的一些代码和 CodeProject 示例中的代码.您可以在一个函数中设置窗口位置和大小.无需再次设置 Console.WindowHeightConsole.WindowWidth.这就是我的班级的样子:

                  I have used some of your code and code from the CodeProject sample. You can set window location and size both in a single function. No need to set Console.WindowHeight and Console.WindowWidth again. This is how my class looks:

                  class Program
                  {
                      const int SWP_NOZORDER = 0x4;
                      const int SWP_NOACTIVATE = 0x10;
                  
                      [DllImport("kernel32")]
                      static extern IntPtr GetConsoleWindow();
                  
                  
                      [DllImport("user32")]
                      static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter,
                          int x, int y, int cx, int cy, int flags);
                  
                      static void Main(string[] args)
                      {
                          Console.WindowWidth = 50;
                          Console.WindowHeight = 3;
                          Console.BufferWidth = 50;
                          Console.BufferHeight = 3;
                          Console.BackgroundColor = ConsoleColor.Black;
                          Console.ForegroundColor = ConsoleColor.DarkMagenta;
                  
                          var screen = System.Windows.Forms.Screen.PrimaryScreen.Bounds;
                          var width = screen.Width;
                          var height = screen.Height;
                  
                          SetWindowPosition(100, height - 300, 500, 100);
                          Console.Title = "My Title";
                          Console.WriteLine("");
                          Console.Write(" Press any key to close this window ...");
                  
                          Console.ReadKey();
                      }
                  
                  
                      /// <summary>
                      /// Sets the console window location and size in pixels
                      /// </summary>
                      public static void SetWindowPosition(int x, int y, int width, int height)
                      {
                          SetWindowPos(Handle, IntPtr.Zero, x, y, width, height, SWP_NOZORDER | SWP_NOACTIVATE);
                      }
                  
                      public static IntPtr Handle
                      {
                          get
                          {
                              //Initialize();
                              return GetConsoleWindow();
                          }
                      }
                  
                  }
                  

                  这篇关于在屏幕左下角放置一个小控制台窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                    <tbody id='LDi8b'></tbody>

                  <small id='LDi8b'></small><noframes id='LDi8b'>

                    <bdo id='LDi8b'></bdo><ul id='LDi8b'></ul>
                    <tfoot id='LDi8b'></tfoot>

                      • <i id='LDi8b'><tr id='LDi8b'><dt id='LDi8b'><q id='LDi8b'><span id='LDi8b'><b id='LDi8b'><form id='LDi8b'><ins id='LDi8b'></ins><ul id='LDi8b'></ul><sub id='LDi8b'></sub></form><legend id='LDi8b'></legend><bdo id='LDi8b'><pre id='LDi8b'><center id='LDi8b'></center></pre></bdo></b><th id='LDi8b'></th></span></q></dt></tr></i><div id='LDi8b'><tfoot id='LDi8b'></tfoot><dl id='LDi8b'><fieldset id='LDi8b'></fieldset></dl></div>
                      • <legend id='LDi8b'><style id='LDi8b'><dir id='LDi8b'><q id='LDi8b'></q></dir></style></legend>