WPF命令提示符
介紹 WPF命令提示符是一個命令列控制檯,附帶了許多功能,包括: 儲存/載入不同的控制檯設定(或使用內部預設值)儲存/載入不同的命令historiesSave /負載風格主題(或者使用內部預設值)訊息區域背景顏色、字型、字型大小、字型顏色、邊框大小/顏色和填充大小手動或使用themesCommand提示背景顏色、字型、字型大小、字型顏色、邊框大小/顏色和填充大小手動或使用themesInternal或外部命令parsingCommand歷史功能 基本佈局在使用者控制元件中有一個訊息區(RichTextBox)和一個命令提示區(TextBox)。我保持命令提示符在視窗的底部,因為有一個調整大小的問題,我還沒有解決。但是,在使用了一段時間之後,我發現我還是更喜歡視窗底部的命令提示符。提示文字(例如:"C: MyStuff\>")在命令提示符區域中被保護,以供終端使用者更改或刪除。 訊息區包括兩個區域,訊息提示區和訊息文字區: 訊息提示區域包含從命令提示符輸入的文字。訊息文字包含寫入控制檯的文字。 為簡潔起見,這裡並沒有顯示所有的屬性/方法。WPFCommandPrompt的完整MSDN風格文件可以在http://cgdn.blogdns.net:8080/找到。有關大部分功能的示例,請參閱專案演示。這個專案也可以從我的網站http://codegravy.dyndns.org:8080/下載。 背景 WPF命令提示符是我幾個月前開始的一個專案的最終結果,當時我需要一個控制檯應用程式,我正在進行的一個專案。 使用的程式碼 建立一個新的命令提示符非常簡單: 隱藏,複製Code
using WPFCommandPrompt; WPFPrompt commandPrompt = new WPFPrompt(); commandPrompt.ReadLine += new ReadLineEventHandler(ProcessCommand); commandPrompt.Show(); private void ProcessCommand(object sender, ConsoleReadLineEventArgs e) { // Process commands sent from the console here } public void WriteLine(stringoutput) { commandPrompt.WriteLine(output); }
有兩個建構函式可供選擇: 隱藏,複製Code
public WPFPrompt() // Uses default style theme: styleThemeIndex = 0 public WPFPrompt(int styleThemeIndex) // The index of the style theme to use
寫入到控制檯: 隱藏,複製Code
// Sends a string to the console. public void WriteLine(string output) //Sends a string with specified brush color to the console. public void WriteLine(string output, Brush foreground) // Sends a FlowDocument paragraph to the console. public void WriteLine(Paragraph paragraph) // Sends a ConsoleWriteLineEventArgs object to the console. public void WriteLine(object sender, ConsoleWriteLineEventArgs e)
以下基本屬性可以在不建立控制檯視窗的情況下設定,如果不設定或使用預設值,可以從磁碟儲存/載入: 隱藏,收縮,複製Code
// Allow an empty command to be written to the message area. (Default: false). public bool AllowEmptyCommand // The window title public string ConsoleTitle // The assembly version of the console public string ConsoleVersion // Gets or sets the default console height public double DefaultConsoleHeight // Gets or sets the default console width public double DefaultConsoleWidth // Gets or sets the default prompt string (Default: >) public string DefaultPrompt // Gets or sets the delimiter regular expression string. // Default: ((""((?<token>.*?)"")|(?<token>[\w]+))(\s)*) public string Delimiters // Enable or disable the command history (Default: true = enabled) public bool EnableCommandHistory // Automatically try to load the style themes on console startup public bool EnableLoadStyleThemes // Is the command history managed by the console(auto) // or by the user(manual) (Default: false = auto) public bool ManualCommandHistory // Gets or sets the maximum console height. Default is 0, no max size. public double MaxConsoleHeight // Gets or sets the maximum console width. Default is 0, no max size. public double MaxConsoleWidth // Gets or sets the maximum allowed font size of the console. public double MaxFontSize // Gets or sets the minimum console height. Default is 400. public double MinConsoleHeight // Gets or sets the minimum console width. Default is 600. public double MinConsoleWidth // Gets or sets the minimum allowed font size of the console. // Gets or sets the current prompt string public string Prompt // Gets or sets the default style theme index number. public int StyleThemeIndex // Gets or sets the welcome message. Displayed upon console startup. public string WelcomeMessage // Should the console parse commands internally. Default: true. // If false, the user is responsible for parsing the returned command string. public bool UserInternalCommandParsing
風格主題-任何改變的主題不會改變原來的主題。呼叫UpdateStyleTheme()將當前主題的任何更改複製到原始主題,或者呼叫CurrentThemeToNew()從當前主題和所有更改中建立一個新主題。在呼叫UpdateStyleTheme()或CurrentThemeToNew()後,呼叫SaveStyleThemes()來儲存到磁碟。請注意,所提供的樣式主題看起來不錯,但還遠遠不夠好,因為我在UI功能方面做得比在美觀方面做得好得多。如果有人創造了一些好看的主題,請在這裡與大家分享! 的興趣點 儘管我認為在某些類中有太多的程式碼,但它工作得很好。我以後會考慮重新做這件事:)。 歷史 當前版本1.0 本文轉載於:http://www.diyabc.com/frontweb/news5394.html