Refactor dictionary application UI to replace ListBox with TextBox for displaying meanings and enhance responsiveness

This commit is contained in:
vista-man
2025-01-27 22:37:33 +01:00
parent eec73a1d81
commit 29d74ade51
25 changed files with 68 additions and 11 deletions

View File

@@ -10,26 +10,33 @@ namespace DictionaryApp
{
private TextBox wordTextBox;
private Button searchButton;
private ListBox meaningListBox;
private TextBox meaningTextBox;
private static readonly HttpClient client = new HttpClient();
public Program()
{
wordTextBox = new TextBox { Left = 50, Top = 20, Width = 200 };
searchButton = new Button { Text = "Search", Left = 260, Top = 20, Width = 100 };
meaningListBox = new ListBox { Left = 50, Top = 60, Width = 310, Height = 200 };
meaningTextBox = new TextBox { Left = 50, Top = 60, Width = 310, Height = 200, Multiline = true, ScrollBars = ScrollBars.Vertical, ReadOnly = true };
searchButton.Click += new EventHandler(SearchButton_Click);
wordTextBox.KeyDown += new KeyEventHandler(WordTextBox_KeyDown);
this.Resize += new EventHandler(Form_Resize);
Controls.Add(wordTextBox);
Controls.Add(searchButton);
Controls.Add(meaningListBox);
Controls.Add(meaningTextBox);
Text = "Dictionary";
Size = new System.Drawing.Size(400, 300);
}
private void Form_Resize(object? sender, EventArgs e)
{
meaningTextBox.Width = this.ClientSize.Width - 100;
meaningTextBox.Height = this.ClientSize.Height - 100;
}
private void WordTextBox_KeyDown(object? sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
@@ -43,8 +50,7 @@ namespace DictionaryApp
{
string word = wordTextBox.Text;
string? meaning = await GetMeaningFromApi(word);
meaningListBox.Items.Clear();
meaningListBox.Items.Add(meaning ?? "Meaning not found.");
meaningTextBox.Text = meaning ?? "Meaning not found.";
}
private async Task<string?> GetMeaningFromApi(string word)