Example #1
0
        /// <summary>
        /// Method called to update the interface when the data in a textbox or
        /// a label is modified.
        /// </summary>
        /// <param name="sco"></param>
        private void Refresh(StdConsoleObject sco)
        {
            // Mark the starting position and colour of the console.
            int x = Console.CursorLeft;
            int y = Console.CursorTop;

            ConsoleColor fore = Console.ForegroundColor;
            ConsoleColor back = Console.BackgroundColor;

            // Make sure the data being written to the screen is either
            // truncated if too long, or padded if too short, to make the
            // field being shown appear correct.
            string text = string.Empty;

            // Make sure to refresh with password masking characters if this is
            // a password field.
            if (sco is Textbox && ((Textbox)sco).PasswordChar != char.MinValue)
            {
                text = new string(((Textbox)sco).PasswordChar, sco.Text.Length);
            }
            else
            {
                text = sco.Text;
            }

            if (text.Length > sco.Length)
            {
                text = text.Substring(0, sco.Length);
            }

            if (text.Length < sco.Length)
            {
                text = text.PadRight(sco.Length, ' ');
            }

            // Actually write the text
            Console.SetCursorPosition(sco.Location.X, sco.Location.Y);
            Console.BackgroundColor = sco.Background;
            Console.ForegroundColor = sco.Foreground;
            Console.Write(text);

            // Reset the cursor and colour information.
            Console.ForegroundColor = fore;
            Console.BackgroundColor = back;
            Console.SetCursorPosition(x, y);

            // If the field being updated is the "current" field (i.e. the one with the
            // cursor in it), reposition the cursor to accomodate existing text.
            if (sco is Textbox)
            {
                if (((Textbox)sco) == _field)
                {
                    Console.SetCursorPosition(_field.Location.X + _field.Text.Length,
                                              _field.Location.Y);
                }
            }
        }
Example #2
0
        /// <summary>
        /// Method called to update the interface when the data in a textbox or 
        /// a label is modified.
        /// </summary>
        /// <param name="sco"></param>
        private void Refresh(StdConsoleObject sco)
        {
            // Mark the starting position and colour of the console.
            int x = Console.CursorLeft;
            int y = Console.CursorTop;

            ConsoleColor fore = Console.ForegroundColor;
            ConsoleColor back = Console.BackgroundColor;

            // Make sure the data being written to the screen is either
            // truncated if too long, or padded if too short, to make the
            // field being shown appear correct.
            string text = string.Empty;

            // Make sure to refresh with password masking characters if this is
            // a password field.
            if (sco is Textbox && ((Textbox) sco).PasswordChar != char.MinValue)
                text = new string(((Textbox) sco).PasswordChar, sco.Text.Length);
            else
                text = sco.Text;

            if (text.Length > sco.Length)
                text = text.Substring(0, sco.Length);

            if (text.Length < sco.Length)
                text = text.PadRight(sco.Length, ' ');

            // Actually write the text
            Console.SetCursorPosition(sco.Location.X, sco.Location.Y);
            Console.BackgroundColor = sco.Background;
            Console.ForegroundColor = sco.Foreground;
            Console.Write(text);

            // Reset the cursor and colour information.
            Console.ForegroundColor = fore;
            Console.BackgroundColor = back;
            Console.SetCursorPosition(x, y);

            // If the field being updated is the "current" field (i.e. the one with the
            // cursor in it), reposition the cursor to accomodate existing text.
            if (sco is Textbox)
                if (((Textbox) sco) == _field)
                    Console.SetCursorPosition(_field.Location.X + _field.Text.Length,
                        _field.Location.Y);
        }