A simple C # information display board

Source: Internet
Author: User

The presentation board in this article is implemented with a TextBox, because the job requires that I implement a tool class that automatically generates formatted information to a TextBox Displayboardhelper

Using system;using system.collections.generic;using system.linq;using system.text;using  System.Threading.Tasks;namespace DisplayBoard{    public class  displayboardhelper    {        /// < summary>        ///  Event Level          /// </summary>        public enum  loglevel        {             /// <summary>             ///  Commissioning             /// </ summary>            debug = 0,             /// <summary>             ///  Information             ///  </summary>            info = 1,             /// <summary>             ///  Notifications              /// </summary>             NOTICE = 2,             /// <summary>            // /  Warning             /// </summary>             warning = 3,             /// <summary>             ///  Error             /// </ summary>            error = 4,             /// <summary>             ///  Serious              /// </summary>             crit = 5,            /  <summary>            ///  hazards             /// </summary>             ALERT = 6,             /// <summary>             ///  Emergency             /// </summary >            EMERG = 7         }        /// <summary>         ///  print an enumeration of alarm levels into a string          /// </summary>        /// <param  Name= "Level" > event class </param>        /// <param name = "Lang" > Output string language &nbsP CHS: Simplified Chinese  eng: English </param>        /// <returns>< /returns>        private static string leveltostring (loglevel level, string lang =  "CHS")          {            if  (lang ==  "CHS")             {                 switch  (level)                  {                     case LogLevel.DEBUG:  return  "Debug";                     case loglevel.info: return  "Information";                     case loglevel.notice: return   "notice";                     case LogLevel.WARNING: return  "Warning";                     case loglevel.error:  return  "Error";                     case LogLevel.CRIT: return  "Serious";                     case  loglevel.alert: return  "Danger";                     case loglevel.emerg: return  "Emergency";                     default: return  "Unknown";                 }             }             else if  (lang ==  "ENG")              {                 switch  (level)                  {                     case LogLevel.DEBUG: return  "DEBUG";                     case loglevel.info:  return  "INFO";                     case LogLevel.NOTICE: return  "NOTICE";                     case  loglevel.warning: return  "WARNING";                     case LogLevel.ERROR: return  "ERROR" ;                     case LogLevel.CRIT: return  "Crit";                     case loglevel.alert: return   "ALERT";                     case loglevel.emerg: return  "Emerg";                     default: return  "UNKNOWN";                 }             }             else            {                 throw new  Exception (lang +  ": Unknown language type");             }        }        ///  <summary>        ///  add a new log to the specified textbox         ///  </summary>        /// <param name= "TB" > TextBox object </param>        /// <param name= "LogLevel" > Log Level </param>        /// <param name= "LogInfo" > Log information </param>        /// <param name= "lang" > Use Language </param>        public static void addlog ( system.windows.forms.textbox tb,              LogLevel logLevel, string logInfo, string lang =  "CHS")          {             string snewlog  = string. Format ("[{0}][{1}]:{2}\r\n",                 datetime.now.tolongtimestring (),                 leveltostring (Loglevel, lang),                 loginfo);       &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;TB. TEXT&NBSP;+=&NBSP;SNEWLOG;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;TB. Select (TB. textlength, 0);             tb. Scrolltocaret ();        }         /// <summary>        ///  See if the textbox's settings conform to the library's best use environment (this function is not required and can be optionally called)         /// </ Summary>&nBsp;       /// <param name= "TB" >textbox objects </param>         /// <param name= "Suggestion" > Recommendations (can be viewed when false is returned) </param>        /// <returns>true: Reasonable  false: Unreasonable </returns>        public static bool  Isconfigreasonable (             system.windows.forms.textbox tb,             Out string suggestion)         {             bool isConfigReasonable = true;             suggestion =  "Suggestion: \ n";             //textbox should be set to support multiple lines             if  (TB). Multiline == false)             {                 suggestion +=   "Controls" &NBSP;+&NBSP;TB. name +  "only supports single-line text (Multiline) \ n";                 isConfigReasonable = false;             }            // The textbox should be set to support vertical scroll bar             if  (TB. scrollbars != system.windows.forms.scrollbars.vertical | | &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;TB. Scrollbars != system.windows.forms.scrollbars.both)             {                 suggestion +=  "Controls" &NBSP;+&NBSP;TB. name +  "Missing vertical scroll bar (ScrollBars) \ n";                 isConfigReasonable = false;             }            // The ReadOnly property and the Enable property should be set at least one to ensure that the textbox is read-only              if  (TB. READONLY&NBSP;==&NBSP;FALSE&NBSP;&AMP;&AMP;&NBSP;TB. Enabled == true)             {                 suggestion +=   "Controls" &NBSP;+&NBSP;TB. name +  "can be arbitrarily modified (readonly or enabled) \ n";                  isconfigreasonable = false;            }             //no problem, no suggestion              if  (isconfigreasonable)              {                 suggestion =  "";             }            return  isconfigreasonable;        }    }}

The following is an implementation of this example program, where only one of the dock properties is set to fill textbox

Program code:

using system;using system.collections.generic;using system.componentmodel;using  system.data;using system.drawing;using system.linq;using system.text;using  system.threading.tasks;using system.windows.forms;namespace displayboard{     public partial class formmain : form    {         public formmain ()         {             initializecomponent ();         }        private void formmain_load ( Object sender, eventargs e)         {             //write some logs              displayboardhelper.addLog (this.txtdisplayboard,                  DisplayBoardHelper.LogLevel.DEBUG,  "This is a test message");             displayboardhelper.addlog (this.txtdisplayboard,                  displayboardhelper.loglevel.info ,  "This is a test message");             Displayboardhelper.addlog (this.txtdisplayboard,                  DisplayBoardHelper.LogLevel.NOTICE,  "This is a test message");             displayboardhelper.addlog (This.txtDisplayBoard,                   displayboardhelper.loglevel.warning,  "This is a test message");            displayboardhelper.addlog ( this.txtdisplayboard,                  DisplayBoardHelper.LogLevel.ERROR,  "This is a test message");             displayboardhelper.addlog (this.txtdisplayboard,                  displayboardhelper.loglevel.crit ,  "This is a test message");             Displayboardhelper.addlog (this.txtdisplayboard,                  DisplayBoardHelper.LogLevel.ALERT,  "This is a test message");             displayboardhelper.addlog (This.txtDisplayBoard,                  displayboardhelper.loglevel.emerg,  "This is a test message");             //See if the TextBox's settings match the library's best use environment              string suggestion;             bool b = displayboardhelper.isconfigreasonable (                 this.txtdisplayboard, out  suggestion);            if  (!b)              {                 messagebox.show (suggestion);             }        }     }}

Example of running results

Displayboardhelper.isconfigreasonable usage environment recommendations generated by


END


A simple C # information display board

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.