Console.Title 屬性

定義

取得或設定要顯示於主控台標題列中的標題。

public:
 static property System::String ^ Title { System::String ^ get(); void set(System::String ^ value); };
public static string Title { [System.Runtime.Versioning.SupportedOSPlatform("windows")] get; [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] set; }
public static string Title { [System.Runtime.Versioning.SupportedOSPlatform("windows")] get; [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] [System.Runtime.Versioning.UnsupportedOSPlatform("android")] [System.Runtime.Versioning.UnsupportedOSPlatform("ios")] [System.Runtime.Versioning.UnsupportedOSPlatform("tvos")] set; }
public static string Title { get; set; }
[<get: System.Runtime.Versioning.SupportedOSPlatform("windows")>]
[<set: System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
member this.Title : string with get, set
[<get: System.Runtime.Versioning.SupportedOSPlatform("windows")>]
[<set: System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
[<set: System.Runtime.Versioning.UnsupportedOSPlatform("android")>]
[<set: System.Runtime.Versioning.UnsupportedOSPlatform("ios")>]
[<set: System.Runtime.Versioning.UnsupportedOSPlatform("tvos")>]
member this.Title : string with get, set
member this.Title : string with get, set
Public Shared Property Title As String

屬性值

String

要顯示於主控台標題列中的字串。 此標題字串的最大長度是 24500 個字元。

屬性

例外狀況

在取得作業中,擷取的標題長度超過 24500 個字元。

在設定作業中,指定的標題長度超過 24500 個字元。

在設定作業中,指定的標題是 null

發生 I/O 錯誤。

在不是 Windows 的作業系統上叫用取得作業。

範例

這個範例會示範 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.
open System

printfn $"The current console title is: \"{Console.Title}\""
printfn "  (Press any key to change the console title.)"
Console.ReadKey true |> ignore

Console.Title <- "The title has changed!"
printfn $"Note that the new console title is \"{Console.Title}\"\n  (Press any key to quit.)"
Console.ReadKey true |> ignore


// 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.)
'

適用於