C
C#2y ago
plane26

✅ Is it bad to ask chatGPT about simple things?

For example im making richtext editor and i asked after 5 hours how to insert bold text after clicking at toggle Button (Bold) to wpf richtextbox at current cursor position (I want to work it like WordPad formatting)
3 Replies
plane26
plane26OP2y ago
// Get the current caret position in the RichTextBox
TextPointer caretPosition = rtb.CaretPosition;

// Create a new Run with the typed text
Run run = new Run(e.Text);

// Apply formatting (bold) to the Run
run.FontWeight = FontWeights.Bold;

// Create a new TextRange from the caret position to the next insertion position
TextRange insertionRange = new TextRange(caretPosition, caretPosition);

// Set the text of the insertion range to the typed text
insertionRange.Text = e.Text;

// Apply formatting (bold) to the inserted text
insertionRange.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold);

// Move the caret position to the end of the inserted text
rtb.CaretPosition = insertionRange.End;

// Mark the event as handled to prevent the default insertion of the typed text
e.Handled = true;
// Get the current caret position in the RichTextBox
TextPointer caretPosition = rtb.CaretPosition;

// Create a new Run with the typed text
Run run = new Run(e.Text);

// Apply formatting (bold) to the Run
run.FontWeight = FontWeights.Bold;

// Create a new TextRange from the caret position to the next insertion position
TextRange insertionRange = new TextRange(caretPosition, caretPosition);

// Set the text of the insertion range to the typed text
insertionRange.Text = e.Text;

// Apply formatting (bold) to the inserted text
insertionRange.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold);

// Move the caret position to the end of the inserted text
rtb.CaretPosition = insertionRange.End;

// Mark the event as handled to prevent the default insertion of the typed text
e.Handled = true;
this is the code it works.. im just feeling bad xddd cause it looks simple xd
Anu6is
Anu6is2y ago
is it bad to search for answers on SO? you just need to understand that ChatGPT is just a tool and the answers it gives can sometimes be incorrect. Which mean you need to ensure that you take the time to understand the code it gives you. Which honestly, you should be doing with any solutions you find online How much time you spend trying to figure out something yourself is up to you, just don't let GPT become a crutch that you always run to as it would limit your ability to solve things on your own
plane26
plane26OP2y ago
Oh Thank you <:blushie_cat:1028655887323242546> ❤️
Want results from more Discord servers?
Add your server