示例#1
0
        //----------
        public string editResponseBox()
        {
            // clearRespbuf();
            respoff = 0;
            posresp();

            char inpkey;

            for (;;)
            {
                Char inpchr = Useful.getKeyPress(out inpkey);
                if ((inpchr >= ' ') && (inpchr <= '~'))
                {
                    Console.Write(inpchr);
                    respbuf[respoff++] = inpchr;
                    if (respoff >= maxoff)
                    {
                        Console.Beep();
                        respoff = respoff % maxoff;
                    }
                    posresp();
                    continue;
                }
                if ((inpchr == 8) || (inpkey == (int)ConsoleKey.Backspace))
                {
                    respoff--;
                    if (respoff < 0)
                    {
                        Console.Beep();
                        respoff = (respoff + maxoff) % maxoff;
                    }
                    posresp();

                    Console.Write(' ');
                    respbuf[respoff] = ' ';
                    posresp();
                    continue;
                }
                if ((inpchr == 9) && (inpkey == (int)ConsoleKey.Tab))
                {
                    break;
                }
                if (inpkey == (int)ConsoleKey.Enter)
                {
                    int scrrow   = respoff / maxcol;
                    int scrcol   = respoff - scrrow * maxcol;
                    int respoff2 = respoff;
                    respoff2 -= scrcol;
                    respoff2 += maxcol;
                    for (int ii = respoff; ii < respoff2; ii++)
                    {
                        Console.Write(' ');
                        respbuf[ii] = ' ';
                    }
                    respoff = respoff2;
                    if (respoff >= maxoff)
                    {
                        Console.Beep();
                        respoff = respoff % maxoff;
                    }
                    posresp();
                    continue;
                }

                if ((inpchr == 0) && (inpkey == (int)ConsoleKey.RightArrow))
                {
                    respoff++;
                    if (respoff >= maxoff)
                    {
                        Console.Beep();
                        respoff = respoff % maxoff;
                    }
                    posresp();
                    continue;
                }
                if ((inpchr == 0) && (inpkey == (int)ConsoleKey.LeftArrow))
                {
                    respoff--;
                    if (respoff < 0)
                    {
                        Console.Beep();
                        respoff = (respoff + maxoff) % maxoff;
                    }
                    posresp();
                    continue;
                }
                if ((inpchr == 0) && (inpkey == (int)ConsoleKey.UpArrow))
                {
                    respoff -= maxcol;
                    if (respoff < 0)
                    {
                        Console.Beep();
                        respoff += maxoff;
                    }
                    posresp();
                    continue;
                }
                if ((inpchr == 0) && (inpkey == (int)ConsoleKey.DownArrow))
                {
                    respoff += maxcol;
                    if (respoff >= maxoff)
                    {
                        Console.Beep();
                        respoff -= maxoff;
                    }
                    posresp();
                    continue;
                }
                if ((inpchr == 0) && (inpkey == (int)ConsoleKey.Tab))
                {
                    Console.SetCursorPosition(10, 24);
                    Console.Write("tab<<<");
                    Console.Beep();
                    posresp();
                    continue;
                }
                if ((inpchr == 0) && (inpkey == (int)ConsoleKey.Insert))
                {
                    Console.SetCursorPosition(10, 24);
                    Console.Write("insert");
                    Console.Beep();
                    posresp();
                    continue;
                }
                if ((inpchr == 0) && (inpkey == (int)ConsoleKey.Delete))
                {
                    Console.SetCursorPosition(10, 24);
                    Console.Write("delete");
                    Console.Beep();
                    posresp();
                    continue;
                }
            } // end for()

            int offb = 0, offx = 0;

            for (int ii = 0; ii < respbuf.Length; ii++)
            {
                offb = ii;
                if (respbuf[ii] != ' ')
                {
                    break;
                }
            }

            for (int ii = respbuf.Length - 1; ii > 0; ii--)
            {
                offx = ii;
                if (respbuf[ii] != ' ')
                {
                    break;
                }
            }

            StringBuilder result = new StringBuilder();
            char          last   = ' ';

            for (int ii = offb; ii <= offx; ii++)
            {
                if ((last == ' ') && (respbuf[ii] == ' '))
                {
                    continue;
                }
                result.Append(respbuf[ii]);
                last = respbuf[ii];
            }
            return(result.ToString().ToLower());
        }