Console.Title 属性

定义

获取或设置要显示在控制台标题栏中的标题。Gets or sets the title to display in the console title bar.

public:
 static property System::String ^ Title { System::String ^ get(); void set(System::String ^ value); };
public static string Title { get; set; }
member this.Title : string with get, set
Public Shared Property Title As String

属性值

要在控制台的标题栏中显示的字符串。The string to be displayed in the title bar of the console. 标题字符串的最大长度是 24500 个字符。The maximum length of the title string is 24500 characters.

异常

在获取操作中,检索到的标题长度超过 24500 个字符。In a get operation, the retrieved title is longer than 24500 characters.

在集运算中,指定的标题长度超过 24500 个字符。In a set operation, the specified title is longer than 24500 characters.

在集运算中,指定的标题是 nullIn a set operation, the specified title is null.

出现 I/O 错误。An I/O error occurred.

get 操作在 Windows 之外的操作系统上调用。The get operation is invoked on an operating system other than Windows.

示例

此示例演示 Title 属性。This example demonstrates the Title property. 该示例显示操作系统窗口的当前标题,等待按键,然后显示一个新标题。The example displays the current title of the operating system window, waits for a key press, then displays a new title.

// This example demonstrates the Console.Title property.
using namespace System;
int main()
{
   Console::WriteLine( "The current console title is: \"{0}\"", Console::Title );
   Console::WriteLine( "  (Press any key to change the console title.)" );
   Console::ReadKey( true );
   Console::Title = "The title has changed!";
   Console::WriteLine( "Note that the new console title is \"{0}\"\n"
   "  (Press any key to quit.)", Console::Title );
   Console::ReadKey( true );
}

/*
This example produces the following results:

>myTitle
The current console title is: "Command Prompt - myTitle"
  (Press any key to change the console title.)
Note that the new console title is "The title has changed!"
  (Press any key to quit.)

*/
// This example demonstrates the Console.Title property.
using System;

class Sample 
{
    public static void Main() 
    {
    Console.WriteLine("The current console title is: \"{0}\"",
                      Console.Title);
    Console.WriteLine("  (Press any key to change the console title.)");
    Console.ReadKey(true);
    Console.Title = "The title has changed!";
    Console.WriteLine("Note that the new console title is \"{0}\"\n" +
                      "  (Press any key to quit.)", Console.Title);
    Console.ReadKey(true);
    }
}
/*
This example produces the following results:

>myTitle
The current console title is: "Command Prompt - myTitle"
  (Press any key to change the console title.)
Note that the new console title is "The title has changed!"
  (Press any key to quit.)

*/
' This example demonstrates the Console.Title property.
Class Sample
   Public Shared Sub Main()
      Console.WriteLine("The current console title is: ""{0}""", Console.Title)
      Console.WriteLine("  (Press any key to change the console title.)")
      Console.ReadKey(True)
      Console.Title = "The title has changed!"
      Console.WriteLine("Note that the new console title is ""{0}""" & vbCrLf & _
                        "  (Press any key to quit.)", Console.Title)
      Console.ReadKey(True)
   End Sub
End Class
'
'This example produces the following results:
'
'>myTitle
'The current console title is: "Command Prompt - myTitle"
'  (Press any key to change the console title.)
'Note that the new console title is "The title has changed!"
'  (Press any key to quit.)
'

适用于