-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChatOutputControl.cs
62 lines (57 loc) · 2.37 KB
/
ChatOutputControl.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace chat_enricher
{
public partial class ChatOutputControl : UserControl
{
public ChatOutputControl()
{
InitializeComponent();
//Create the chat message columns and adjust the styling
this.chatMessagesGridView.Columns.Add("received", "Received");
this.chatMessagesGridView.Columns.Add("sent", "Sent");
this.chatMessagesGridView.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
this.chatMessagesGridView.Columns[0].DividerWidth = 5;
this.chatMessagesGridView.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
//Called when a new message is received.
//Adds the message to the relevant chat message data grid view
public void NewMessage(string message, bool currentUser)
{
if (currentUser) {
Invoke(new Action(() => {
int rowIndex = this.chatMessagesGridView.Rows.Add(null, message);
DataGridViewCellStyle sentStyle = new DataGridViewCellStyle();
sentStyle.BackColor = Color.CornflowerBlue;
this.chatMessagesGridView.Rows[rowIndex].Cells[1].Style = sentStyle;
}));
}
else
{
Invoke(new Action(() => {
int rowIndex = this.chatMessagesGridView.Rows.Add(message, null);
DataGridViewCellStyle receivedStyle = new DataGridViewCellStyle();
receivedStyle.BackColor = Color.Gray;
this.chatMessagesGridView.Rows[rowIndex].Cells[0].Style = receivedStyle;
}));
}
}
//Allows the chat metadata textbox to be repopulated with different text
public void UpdateMetadata(string metadata)
{
Invoke(new Action(() => { this.chatMetadataTextBox.Text = metadata; }));
}
//Prevents cell selection without disabling the data grid view
private void ChatMessagesGridView_SelectionChanged(object sender, EventArgs e)
{
chatMessagesGridView.ClearSelection();
}
}
}