Ejemplo n.º 1
0
        private string JustifyString(string str, LineJustification justification)
        {
            string justified  = str;
            int    whitespace = WIDTH - str.Length;

            if (whitespace > 0)
            {
                switch (justification)
                {
                case LineJustification.Left:
                    // do nothing, already left justified
                    break;

                case LineJustification.Center:
                    if (whitespace % 2 == 0)
                    {
                        justified = WhiteSpace(whitespace / 2) + str + WhiteSpace(whitespace / 2);
                    }
                    else
                    {
                        justified = WhiteSpace(whitespace / 2) + str + WhiteSpace((whitespace - 1) / 2);
                    }

                    break;

                case LineJustification.Right:
                    justified = WhiteSpace(whitespace) + str;
                    break;
                }
            }

            return(justified);
        }
Ejemplo n.º 2
0
        private string JustifyString(string str, LineJustification justification)
        {
            string justified = str;
            int whitespace = WIDTH - str.Length;

            if (whitespace > 0)
            {
                switch (justification)
                {
                    case LineJustification.Left:
                        // do nothing, already left justified
                        break;
                    case LineJustification.Center:
                        if (whitespace % 2 == 0)
                        {
                            justified = WhiteSpace(whitespace / 2) + str + WhiteSpace(whitespace / 2);
                        }
                        else
                        {
                            justified = WhiteSpace(whitespace / 2) + str + WhiteSpace((whitespace - 1) / 2);
                        }

                        break;
                    case LineJustification.Right:
                        justified = WhiteSpace(whitespace) + str;
                        break;
                }
            }

            return justified;
        }
Ejemplo n.º 3
0
        public void WriteStringOnLine(string str, DisplayLine line = DisplayLine.LineOne, LineJustification justification = LineJustification.Left)
        {
            SendCommand((int)line);

            if (justification != LineJustification.Left)
            {
                str = JustifyString(str, justification);
            }

            byte[] asciiValues = Encoding.ASCII.GetBytes(str);

            for (int i = 0; i < str.Length && i < WIDTH; i++)
            {
                SendData(asciiValues[i]);
            }
        }
Ejemplo n.º 4
0
        public void WriteStringOnLine(string str, DisplayLine line = DisplayLine.LineOne, LineJustification justification = LineJustification.Left)
        {
            SendCommand((int)line);

            if (justification != LineJustification.Left)
            {
                str = JustifyString(str, justification);
            }

            byte[] asciiValues = Encoding.ASCII.GetBytes(str);

            for (int i = 0; i < str.Length && i < WIDTH; i++)
            {
                SendData(asciiValues[i]);
            }
        }