Implement Chat Autoscroll

This commit is contained in:
Alan Moon 2025-06-20 17:08:20 -07:00
parent 9ba107c964
commit 85a0ecc4f4
4 changed files with 16 additions and 2 deletions

View File

@ -63,6 +63,7 @@
rtxtChat.Size = new Size(593, 250);
rtxtChat.TabIndex = 3;
rtxtChat.Text = "";
rtxtChat.TextChanged += rtxtChat_TextChanged;
//
// Chat
//

View File

@ -64,10 +64,16 @@ namespace qtc_net_client_2.Forms
private void rtxtChatbox_KeyDown(object sender, KeyEventArgs e)
{
if(e.KeyCode == Keys.Enter)
if (e.KeyCode == Keys.Enter)
btnSend_Click(sender, e);
}
private void rtxtChat_TextChanged(object sender, EventArgs e)
{
rtxtChat.SelectionStart = rtxtChatbox.Text.Length;
rtxtChat.ScrollToCaret();
}
private void _gatewayService_OnServerMessageReceived(object? sender, EventArgs e)
{
var msgEventArgs = (ServerMessageEventArgs)e;

View File

@ -44,6 +44,7 @@
rtxtChat.Size = new Size(593, 317);
rtxtChat.TabIndex = 6;
rtxtChat.Text = "";
rtxtChat.TextChanged += rtxtChat_TextChanged;
//
// btnSend
//

View File

@ -79,10 +79,16 @@ namespace qtc_net_client_2.Forms
private void rtxtChatbox_KeyPress(object sender, KeyEventArgs e)
{
// mimick clicking send
if(e.KeyCode == Keys.Enter)
if (e.KeyCode == Keys.Enter)
btnSend_Click(sender, e);
}
private void rtxtChat_TextChanged(object sender, EventArgs e)
{
rtxtChat.SelectionStart = rtxtChatbox.Text.Length;
rtxtChat.ScrollToCaret();
}
private void Messages_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
if (e.NewItems != null && e.NewItems.Count > 0)