Welcome to the SRP Forum! Please refer to the SRP Forum FAQ post if you have any questions regarding how the forum works.

How to retain the selected text after losing focus

I am trying to make a form that lets our users maintain various pieces of text (which must be entered as html). I want to allow the user to bold the selected text, but when I click the bold button, the selection disappears. Is there anyway of retaining the selection after losing focus? I guess I could record the selection on the lost focus, but I was wondering if there was a better way?

See the below image for what I mean:


Comments

  • You can set the Raw Style Bit for this:


    Alternatively, you can programmatically set this style ES_NOHIDESEL (0x0100).
  • edited May 2021
    Perfect thanks.

    I have noticed another issue as well. It seems that the presence of @tm (new lines) in the edit box causes the selection property to be inaccurate. I will try to figure out exactly what is going on and describe it, but you may already know what I am getting at?
  • Do you suspect it is off by one character for each line in the edit box?
  • Then I suspect it has to do with the difference between the internal delimiter (@TM, which is one character) and the Windows controls delimiter (CR/LF, which is two characters). I suggest adding an extra character per @TM you see in the string.
  • Good point, that's probably what the issue is.

    Thanks!
Sign In or Register to comment.