Ejemplo n.º 1
0
        private void DisplayError(string text)
        {
            if (InvokeRequired)
            {
                // Invoke UI updates on the UI thread
                BeginInvoke(new Action <string>(DisplayError), text);
                return;
            }

            // Start selection at the end of the text box
            // in order to set the color of the appended text
            MessagesTextBox.SelectionStart  = MessagesTextBox.TextLength;
            MessagesTextBox.SelectionLength = 0;

            // Append text to the text box
            MessagesTextBox.SelectionColor = Color.Red;
            MessagesTextBox.AppendText(text + "\n");
            MessagesTextBox.SelectionColor = ForeColor;

            // Truncate old messages when the text
            // exceeds the maximum number of lines
            MessagesTextBox.SelectionStart = 0;

            MessagesTextBox.SelectionLength = MessagesTextBox.Lines
                                              .Take(MessagesTextBox.Lines.Length - m_maxLines)
                                              .Aggregate(0, (length, line) => length + line.Length + "\n".Length);

            MessagesTextBox.ReadOnly     = false;
            MessagesTextBox.SelectedText = "";
            MessagesTextBox.ReadOnly     = true;

            // Scroll to bottom
            MessagesTextBox.SelectionStart = MessagesTextBox.TextLength;
            MessagesTextBox.ScrollToCaret();
        }
Ejemplo n.º 2
0
 private void RenderMsg(string msg)
 {
     PrintRBot();
     MessagesTextBox.AppendText(msg + "\r\n\r\n");
     MessagesTextBox.ScrollToCaret();             //позволяет прокрутить окно чата до конца
     QuestionTextBox.Clear();
 }
Ejemplo n.º 3
0
 private void MessagesTextBox_SizeChanged(object sender, EventArgs e)
 {
     // Sometimes the scrollbar will fail to update or scroll
     // beyond the bottom of the text box when the text box
     // is resized. Scrolling to the top and then back to the
     // bottom fixes this problem
     MessagesTextBox.Select(0, 0);
     MessagesTextBox.ScrollToCaret();
     MessagesTextBox.Select(MessagesTextBox.TextLength, 0);
     MessagesTextBox.ScrollToCaret();
 }
Ejemplo n.º 4
0
        //обработчик кнопки "Отправить"
        private void BtnSend_Click(object sender, EventArgs e)
        {
            if (QuestionTextBox.Text != "")
            {
                ShowUserMessage();

                CurrentUserMessage = QuestionTextBox.Text;
                ClearCurrentMessageFromSymbols();

                //обработка поиска в браузере
                if (CurrentUserMessage.Contains("что такое"))
                {
                    var stringToFind = CurrentUserMessage.Replace("что такое", "");

                    System.Diagnostics.Process.Start("https://yandex.ru/search/?text=" + stringToFind);

                    PrintRBot();
                    MessagesTextBox.AppendText("Открываю поиск по запросу \"" + stringToFind + "\"\r\n\r\n");

                    MessagesTextBox.ScrollToCaret(); //позволяет прокрутить окно чата до конца.
                    QuestionTextBox.Clear();

                    return;
                }

                //ищем сообщение пользователя в базе
                FindCurrentQuestionIndex();

                if (CurrentQuestionIndex == -1) //если не нашли - показываем ответ по умолчанию
                {
                    ShowDefaultAnswer();
                }
                else
                {
                    ShowAnswer();
                }
            }
            else
            {
                MessageBox.Show("Вы пытаетесь отправить пустое сообщение. Вам не ответят.");
            }

            MessagesTextBox.ScrollToCaret(); //позволяет прокрутить окно чата до конца.
            QuestionTextBox.Clear();
        }