コード例 #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);
        }
コード例 #2
0
ファイル: LCD.cs プロジェクト: bmalicoat/LCDDriver
        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;
        }
コード例 #3
0
ファイル: LCD.cs プロジェクト: bmalicoat/LCDDriver
        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]);
            }
        }
コード例 #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]);
            }
        }