Ejemplo n.º 1
0
 private void MessagesTextBox_TextChanged(object sender, TextChangedEventArgs e)
 {
     if (MessagesTextBox.LineCount > 1000)
     {
         MessagesTextBox.Clear();
     }
 }
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 DownloadBotToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         using (OpenFileDialog ofd = new OpenFileDialog()
         {
             Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*", Multiselect = false, ValidateNames = true
         })
         {
             if (ofd.ShowDialog() == DialogResult.OK)
             {
                 string filename = ofd.FileName;
                 string file     = System.IO.File.ReadAllText(filename);
                 MessagesTextBox.Text = file;
             }
             else
             {
                 MessagesTextBox.AppendText("Не удалось загрузить историю");
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Ejemplo n.º 4
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.º 5
0
        private void MessagesOnCollectionChanged(object sender, NotifyCollectionChangedEventArgs args)
        {
            if (args.Action == NotifyCollectionChangedAction.Add)
            {
                foreach (string message in args.NewItems.OfType <string>())
                {
                    MessagesTextBox.AppendText(message + Environment.NewLine);
                }

                Window window = Window.GetWindow(this);
                if (window == null)
                {
                    return;
                }

                if (window.IsActive && window.WindowState != WindowState.Minimized)
                {
                    MessagesTextBox.ScrollToEnd();
                    return;
                }

                Task.Run(new Action(FlashWhileMinimized));
                window.StartFlashing();
            }
        }
Ejemplo n.º 6
0
 private void AddMessage(string value)
 {
     this.InvokeAction(() =>
     {
         MessagesTextBox.AppendText(value + "\r\n");
     });
 }
Ejemplo n.º 7
0
 /// <summary>
 /// An event raised by the messagesTimer that responsible for updating the messages textbox in the UI
 /// </summary>
 private void UpdateMessagesTextBox(object sender, ElapsedEventArgs e)
 {
     this.Dispatcher.Invoke(() =>
     {
         MessagesTextBox.Text = simulator.SimulationMessages;
         MessagesTextBox.ScrollToEnd();
     });
 }
Ejemplo n.º 8
0
        //метод, распечатывающий имя бота синим цветом перед сообщением
        private void PrintRBot()
        {
            var startOfSelection = MessagesTextBox.TextLength;

            MessagesTextBox.AppendText("R-Bot: ");
            MessagesTextBox.Select(startOfSelection, "R-Bot:".Length);
            MessagesTextBox.SelectionColor = Color.Blue;
        }
Ejemplo n.º 9
0
        //метод, распечатывающий имя бота синим цветом перед сообщением
        private void PrintRBot()
        {
            DateTime date             = DateTime.Now;
            string   outputSunny      = date.ToString("[dd/MM/yyyy HH:mm:ss] ") + "Лучик: ";
            var      startOfSelection = MessagesTextBox.TextLength;

            MessagesTextBox.AppendText(outputSunny);
            MessagesTextBox.Select(startOfSelection, outputSunny.Length);
            MessagesTextBox.SelectionColor = Color.Blue;
        }
Ejemplo n.º 10
0
        //метод, отобращающий пользовательское сообщение
        private void ShowUserMessage()
        {
            var startOfSelection = MessagesTextBox.TextLength;

            MessagesTextBox.AppendText("Вы: ");
            MessagesTextBox.Select(startOfSelection, "Вы:".Length);
            MessagesTextBox.SelectionColor = Color.Green;

            MessagesTextBox.AppendText(QuestionTextBox.Text + "\r\n\r\n");
        }
Ejemplo n.º 11
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.º 12
0
        //метод, отобращающий пользовательское сообщение
        private void ShowUserMessage()
        {
            DateTime date         = DateTime.Now;
            string   str          = Data.Text;
            string   outputPlayer = date.ToString("[dd/MM/yyyy HH:mm:ss] ") + str + ": ";

            var startOfSelection = MessagesTextBox.TextLength;

            MessagesTextBox.AppendText(outputPlayer);
            MessagesTextBox.Select(startOfSelection, outputPlayer.Length);
            MessagesTextBox.SelectionColor = Color.Green;
            MessagesTextBox.AppendText(QuestionTextBox.Text + "\r\n\r\n");
        }
Ejemplo n.º 13
0
        private void OnViewModelPropChanged(object sender, PropertyChangedEventArgs e)
        {
            var vm = DataContext as GameSurfaceViewModel;

            if (vm == null)
            {
                return;
            }

            // TODO No scrolljacking if user manually scrolled.
            if (e.PropertyName == nameof(GameSurfaceViewModel.Messages))
            {
                MessagesTextBox.ScrollToEnd();
            }
        }
Ejemplo n.º 14
0
        //метод, показывающий ответ на вопрос, который есть в базе.
        private void ShowAnswer()
        {
            var rand = new Random();

            //берем случайный ответ из списка ответов.
            CurrentAnswerIndex = rand.Next(QuestionsList[CurrentQuestionIndex].Answers.Count);

            PrintRBot();
            StringBuilder sb = new StringBuilder();

            sb.Append(QuestionsList[CurrentQuestionIndex].Answers[CurrentAnswerIndex]);
            sb.Append("\r\n\r\n");

            MessagesTextBox.AppendText(sb.ToString());
        }
Ejemplo n.º 15
0
 private void device_Input(object sender, MidiInputEventArgs args)
 {
     try
     {
         Invoke(new Action(delegate()
         {
             MessagesTextBox.AppendText(
                 args.Message.ToString() +
                 Environment.NewLine);
         }));
     }
     catch
     {
     }
 }
Ejemplo n.º 16
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();
        }
Ejemplo n.º 17
0
        private void OnPropertyChanged(object sender, PropertyChangedEventArgs args)
        {
            switch (args.PropertyName)
            {
            case nameof(ChatViewModel.Title):
                UpdateTitle();
                return;

            case nameof(ChatViewModel.Messages):
                MessagesTextBox.Clear();
                foreach (string message in ((ChatViewModel)DataContext).Messages)
                {
                    MessagesTextBox.AppendText(message);
                }

                break;
            }
        }
Ejemplo n.º 18
0
 //метод, показывающий ответ по умолчанию
 private void ShowDefaultAnswer()
 {
     PrintRBot();
     MessagesTextBox.AppendText("Я тебя не понимаю.\r\n\r\n");
 }
Ejemplo n.º 19
0
 private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
 {
     MessagesTextBox.Focus();
     MessagesTextBox.CaretIndex = MessagesTextBox.Text.Length;
     MessagesTextBox.ScrollToEnd();
 }
Ejemplo n.º 20
0
 private void InputDevice_ChannelMessageReceived(object sender, ChannelMessageEventArgs e)
 {
     MessagesTextBox.Text += $"Channel: {e.Message.Message}\n";
     MessagesTextBox.ScrollToEnd();
 }
Ejemplo n.º 21
0
 //обработчик пункта меню "Очистить чат"
 private void очиститьЧатToolStripMenuItem_Click(object sender, EventArgs e)
 {
     MessagesTextBox.Clear();
 }
Ejemplo n.º 22
0
 //обработчик пункта меню "Очистить чат"
 private void ClearChatToolStripMenuItem_Click(object sender, EventArgs e)
 {
     MessagesTextBox.Clear();
 }