Skip to content

GenerateUserControl.cs

suncloudsmoon edited this page Dec 8, 2024 · 1 revision

Overview

GenerateUserControl is a custom user control within the TextCraft application. Its primary function is to handle user interactions for generating content, either text or images, based on user prompts. The control includes functionality for adjusting parameters like temperature, which influences the creativity or randomness of the AI's responses. It also handles user inputs through text boxes and buttons, and integrates with the main application add-in to manipulate the active document in Microsoft Office.

Public Members

Variables

  • CultureHelper: A static readonly field of type CultureLocalizationHelper used for handling localized strings within the control.

Functions

  • None explicitly declared in the provided code snippet.

Private Members

Variables

  • None explicitly declared in the provided code snippet.

Functions

  • MatchScrollBarTemperature(): Updates the temperature value label to reflect the current position of the temperature track bar, considering the culture's decimal point settings.

  • GetTemperature(): Calculates and returns the temperature value based on the track bar's position, scaled appropriately.

  • GenerateButton_Click(object sender, EventArgs e): An asynchronous event handler that is triggered when the generate button is clicked. It retrieves the user's prompt, checks if it's not empty, and then uses the AI model to generate either text or an image based on the model type. The generated content is then inserted into the active document at the user's current selection.

  • PromptTextBox_KeyDown(object sender, KeyEventArgs e): An event handler for keydown events in the prompt text box. It handles shortcuts like Ctrl+Enter to generate content and Ctrl+Backspace to delete words efficiently.

  • TemperatureTrackBar_Scroll(object sender, EventArgs e): An event handler for the scroll event of the temperature track bar, which updates the displayed temperature value accordingly.

Events

  • GenerateButton_Click(object sender, EventArgs e): Handles the click event for the generate button, initiating the content generation process.

  • PromptTextBox_KeyDown(object sender, KeyEventArgs e): Handles keydown events in the prompt text box, providing shortcuts for generating content and efficient text deletion.

  • TemperatureTrackBar_Scroll(object sender, EventArgs e): Handles the scroll event of the temperature track bar, updating the temperature display in real-time.

Clone this wiki locally