fix my chatbox code when I press enter inside the chatbox instead of animating out the…
- User
fix my chatbox code when I press enter inside the chatbox instead of animating out the chatbox instantly goes away fix and return entire code no commentary.
using System; using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using Clowd.Clipboard;
namespace ByteBreath { public partial class ChatBox : Form { private Form1 _form1;
code - Assistant
- User
adjust this if needed and send it back
private async void textBox1_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)Keys.Escape) { e.Handled = true; textBox1.Clear(); await AnimateToPositionAsync(Screen.FromControl(this).WorkingArea.Bottom, false); return; }
codeif (e.KeyChar == (char)Keys.Enter) { e.Handled = true; if (!string.IsNullOrWhiteSpace(textBox1.Text)) { if (_form1.FishSpeechMode) _form1.GimmieFish(textBox1.Text, false); if (_form1.ZonosTTSMode) _form1.GimmieLocoz(textBox1.Text); if (_form1.IndexTTSBool) _form1.IndexAPI(textBox1.Text); await ClipboardWpf.SetTextAsync(textBox1.Text); textBox1.Clear(); // Do animation then hide after completion await AnimateToPositionAsync(Screen.FromControl(this).WorkingArea.Bottom, false); } }}
- Assistantcsharp
private async void textBox1_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)Keys.Escape) { e.Handled = true; textBox1.Clear(); await AnimateToPositionAsync(Screen.FromControl(this).WorkingArea.Bottom, false); return; } if (e.KeyChar == (char)Keys.Enter) { e.Handled = true; string text = textBox1.Text.Trim(); if (!string.IsNullOrEmpty(text)) { if (_form1.FishSpeechMode) _form1.GimmieFish(text, false); if (_form1.ZonosTTSMode) _form1.GimmieLocoz(text); if (_form1.IndexTTSBool) _form1.IndexAPI(text); await ClipboardWpf.SetTextAsync(text); textBox1.Clear(); await AnimateToPositionAsync(Screen.FromControl(this).WorkingArea.Bottom, false); } } } - User
none of that fixed the problem heres my code on form1 that opens the chatbox maybe thats the problem?
if (e.VirtualKeyCode == (int)VirtualKeyCode.RETURN) { if (UseChatbox) { chatBox.Visible = false; chatBox.Show(this); chatBox.Poop(); chatBox.textBox1.Focus(); chatBox.textBox1.Select(); textBox1.Select(); } }
- Assistantcsharp
if (e.VirtualKeyCode == (int)VirtualKeyCode.RETURN) { if (UseChatbox) { if (!chatBox.Visible) { chatBox.Show(this); chatBox.Poop(); } else { // If chatBox is already visible, just bring it to front and focus the textbox chatBox.BringToFront(); } chatBox.textBox1.Focus(); chatBox.textBox1.Select(); textBox1.Select(); } }Explanation:
- Removed
chatBox.Visible = false;beforeShow()which causes the chatBox to hide immediately, thus no animation. - Added a check to only call
Show()andPoop()if chatBox isn't already visible, preventing unnecessary hides and shows. - When already visible, just bring it front.
- Make sure to focus and select textbox after showing/animating.
- Removed