Elegant Log Window in WinForms C# -
I'm looking for ideas in an effective way to apply a log window to windows applications I am In the past I have used many textbox and rich textbox but I am still not completely satisfied with the functionality.
This log is intended to provide users with the latest history of various events, mainly used in data-gathering applications where one can be curious that one How to complete special transactions In this case, the logs do not need to be permanently saved in the file.
First of all, some proposed requirements:
- Efficient and fast; If hundreds of lines are written immediately to log in succession, then it needs to consume minimal resources and time.
- Be able to offer a variable scrollback of 2000 lines or so, now nothing is unnecessary.
- Highlighting and color are preferred Font effects are not required.
- Trim the lines to reach the scrollback limit automatically.
- Scroll down when new data is added automatically.
- Bonus but not required: Pause Auto-scrolling during manual interaction, such as browsing user history.
I'm still using to write and trim the log:
The following code I use (which I call from another thread) :
// rtblog is a rich textbox / _maxline an int public zero epilogue (string s, color c, balls b newline) {if (RtbLog.InvokeRequired) {object] args = { S, c, bNewLine}; RtbLog.Invoke (new AppendLogDel, Args); Return; } Try {rtbLog.SelectionColor = c; RtbLog.AppendText (s); If (bNewLine) rtbLog.AppendText (EnvironmentalNewLine); TrimLog (); RtbLog.SelectionStart = rtbLog.TextLength; RtbLog.ScrollToCaret (); RtbLog.Update (); } Hold (Exception exc) {// Exception Handling}} Private Zero TrimLog () {{Extra additional lines to save time as buffer (rtbLog.Lines.Length & lt; _MaxLines + 10) {return; } Else {string [] sTemp = rtxtLog.Lines; String [] sNew = new string [_MaxLines]; Int iLineOffset = sTemp.Length - _MaxLines; (New news for [n] = sTemp [iLineOffset]; iLineOffset ++;} RtbLog.Lines = sNew;}} (exception n = 0; n ++) / Exception handling}}
The problem with this approach is that whenever the trimol is called, I lose color formatting. It works perfectly with regular text box (Certainly with modification).
The search for this solution is never really satisfactory, some line in the rich textbox Instead of the result, the character counts to make an additional deduction. I have also seen ListBoxes but have not tried to do it successfully.
I recommend that you do not use the control as your login, rather write a log archive class instead of the property you want (not including the display properties )
Then type a little code which will be used to archive that collection It is necessary to dump different types of user interface elements. Personally, I will put the SendToEditControl
and SendToListBox
method in my logging object I will probably filter these methods I will add capabilities.
The only time you can understand the UI log, give you the best performance, and more importantly, when you reduce the UI Overhead, the logs are changing rapidly
< P> The important thing is that your logging is not to divide it into a piece of UI, this is a mistake, you may want to run without heading someday.In the long run, a good UI for Logger is probably a custom control but in less time, you want to separate your logging from any specific UI piece.
Comments
Post a Comment