private void btnSend_Click(object sender, EventArgs e) { Client.uMessageLine row = new Client.uMessageLine(); row.SetWidth(this.Width - 65); row.SetMessageContent(txtInput.Text); lbMain.Controls.Add(row); _onSendButtonPressed?.Invoke(txtInput.Text, RemoteEndpoint); txtInput.Text = ""; if (!lbMain.AutoScroll) { if (GetContentHeight() > 170) { lbMain.AutoScroll = true; } } lbMain.ScrollControlIntoView(row); }
public void AppendMessage(string message) { if (this.InvokeRequired) { this.BeginInvoke((MethodInvoker) delegate() { Client.uMessageLine row = new Client.uMessageLine(); row.SetWidth(this.Width - 65); row.SetMessageContent(message, UserNickname, false); lbMain.Controls.Add(row); if (!lbMain.AutoScroll) { if (GetContentHeight() > 170) { lbMain.AutoScroll = true; } } lbMain.ScrollControlIntoView(row); }); } else { Client.uMessageLine row = new Client.uMessageLine(); row.SetWidth(this.Width - 65); row.SetMessageContent(message, UserNickname, false); lbMain.Controls.Add(row); if (!lbMain.AutoScroll) { if (GetContentHeight() > 170) { lbMain.AutoScroll = true; } } lbMain.ScrollControlIntoView(row); } }